0

I have this following scenario. I have a usercontrol in my page which has a radio button. This control is placed in a page, on click of a button in the page I need to know if the radio button is selected. This is a client event click event of the button as I have to show a confirmation message box i.e. if user clicks yes only then I have to do the remaining operation. Can you guide me what would be the best way to find if the radio button in the userControl is selected.

Thanks

2
  • var radioButtonObject = document.getElementById('radio_id'); if (radioButtonObject.checked) { /* do this */} else { /* do that*/ } Commented Jul 5, 2012 at 15:25
  • @Mathletics i have tried something like fallowing on server on click of radiobutton and use the IsYes value in js file ScriptManager.RegisterClientScriptBlock(this.Page, this.Page.GetType(), "IsYes", "var IsYes = true;", true); Commented Jul 5, 2012 at 15:27

1 Answer 1

1

If the page needs to know, add a public property to the UC:

public bool IsRadioSelected { get { return Radio.Checked; } }

You can also have the RadioButton postback on changing the check by setting the AutoPostBack property to true.

EDIT: For client script, you could also add a public property to the RadioButton:

public string RadioClientID { get { return Radio.ClientID; } }

Then in javascript, you can do:

var radioButtonObject = document.getElementById('<%= RadioClientID %>'); 
if (radioButtonObject.checked) { /* do this */} else { /* do that*/ }

The problem is the ID of the radio button in client script looks like "ct100_Body_somecontainer_RadioID" and can't be easily directly referenced. The approach above is safer.

Sign up to request clarification or add additional context in comments.

1 Comment

i have a public property in the control, problem for me is getting the value in javascript, i am not able to get the control and property in script.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.