Write onclick event for code behind file page
-
Hi, I have some dynamic radio buttons on my web page and want to write some code for an onclick event with in the code behind file page. Any ideas would be helpful! Thanks for your time, Vani
Well u can do it this way example public class WebForm10 : System.Web.UI.Page { protected System.Web.UI.WebControls.RadioButton rbtn1; protected System.Web.UI.WebControls.RadioButton rbtn2; private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { rbtn1.Attributes.Add("onclick","alert('rbtn1.Selected')"); rbtn2.Attributes.Add("onclick","alert('rbtn2.Selected')"); //OR Like this rbtn1.Attributes["onclick"] = "alert('rbtn1.Selected')"; rbtn2.Attributes["onclick"] = "alert('rbtn1.Selected')"; } } Wyx :cool:
-
Well u can do it this way example public class WebForm10 : System.Web.UI.Page { protected System.Web.UI.WebControls.RadioButton rbtn1; protected System.Web.UI.WebControls.RadioButton rbtn2; private void Page_Load(object sender, System.EventArgs e) { if(!IsPostBack) { rbtn1.Attributes.Add("onclick","alert('rbtn1.Selected')"); rbtn2.Attributes.Add("onclick","alert('rbtn2.Selected')"); //OR Like this rbtn1.Attributes["onclick"] = "alert('rbtn1.Selected')"; rbtn2.Attributes["onclick"] = "alert('rbtn1.Selected')"; } } Wyx :cool:
-
Awesome! The alert works! I was trying to set the back ground color for the radio button - tried something like rb.Backcolor.Blue - but it comes back with error message - since rb is defined as radio button it cannot be converted to string? Thanks.