Reputation: 1141
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
Upvotes: 0
Views: 541
Reputation: 50728
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.
Upvotes: 1