How to get radiobutton value inside a button click event. [modified]
-
Hi , I have added radio button dynamically during page loading.I have two questiions. 1) when I click radio button, have to call javascript function. 2) Get value of radio button(RadioButtonId.Value) when I click NextButton. // Adding radio buttons Dynamically to panel control. HtmlInputRadioButton rdb = new HtmlInputRadioButton(); for (int i = 0; i < dvForDisplay.Count; i++) { rdb.ID = dvForDisplay[i]["RadioButtonId"].ToString(); rdb.Value = dvForDisplay[i]["PaymentGateway"].ToString(); panelInternational.Controls.Add(rdb); } // Button click event protected void btnNext_Click(object sender, EventArgs e) { here I want to get radion button value. } Can anybody help me.. Thanks
modified on Friday, April 25, 2008 12:18 AM
-
Hi , I have added radio button dynamically during page loading.I have two questiions. 1) when I click radio button, have to call javascript function. 2) Get value of radio button(RadioButtonId.Value) when I click NextButton. // Adding radio buttons Dynamically to panel control. HtmlInputRadioButton rdb = new HtmlInputRadioButton(); for (int i = 0; i < dvForDisplay.Count; i++) { rdb.ID = dvForDisplay[i]["RadioButtonId"].ToString(); rdb.Value = dvForDisplay[i]["PaymentGateway"].ToString(); panelInternational.Controls.Add(rdb); } // Button click event protected void btnNext_Click(object sender, EventArgs e) { here I want to get radion button value. } Can anybody help me.. Thanks
modified on Friday, April 25, 2008 12:18 AM
To get the value of the radiobutton, you need to add the controls to the panel again Dinamically added controls are not regenerated when the page is posted back If you are adding the controls in the pageload inside an ispostback condition, get it out of that condition, and let the controls be added each time the page os posted back
Alexei Rodriguez
-
To get the value of the radiobutton, you need to add the controls to the panel again Dinamically added controls are not regenerated when the page is posted back If you are adding the controls in the pageload inside an ispostback condition, get it out of that condition, and let the controls be added each time the page os posted back
Alexei Rodriguez
Hi, thanks for your reply. Can you tell me How to read controls from panel control? HtmlInputRadioButton rdb = new HtmlInputRadioButton(); for (int i = 0; i < dvForDisplay.Count; i++) { rdb.ID = dvForDisplay[i]["RadioButtonId"].ToString(); rdb.Value = dvForDisplay[i]["PaymentGateway"].ToString(); panelInternational.Controls.Add(rdb); } Thanks
-
Hi, thanks for your reply. Can you tell me How to read controls from panel control? HtmlInputRadioButton rdb = new HtmlInputRadioButton(); for (int i = 0; i < dvForDisplay.Count; i++) { rdb.ID = dvForDisplay[i]["RadioButtonId"].ToString(); rdb.Value = dvForDisplay[i]["PaymentGateway"].ToString(); panelInternational.Controls.Add(rdb); } Thanks
For Each ctrl As Control In panelInternational.Controls If TypeOf ctrl Is RadioButton Then Dim radio As RadioButton = CType(ctrl, RadioButton) 'Do what you want with radio variable wich has a control End If Next
In this example, im using radiobuttons and not htmlradiobuttons If you are adding many radiobuttons to the panel i would recomend using a radiobuttonList (And add all the options you need to a single control) Then to retrieve the selected value, Just use radiobuttonList.selectedValue
Alexei Rodriguez
-
For Each ctrl As Control In panelInternational.Controls If TypeOf ctrl Is RadioButton Then Dim radio As RadioButton = CType(ctrl, RadioButton) 'Do what you want with radio variable wich has a control End If Next
In this example, im using radiobuttons and not htmlradiobuttons If you are adding many radiobuttons to the panel i would recomend using a radiobuttonList (And add all the options you need to a single control) Then to retrieve the selected value, Just use radiobuttonList.selectedValue
Alexei Rodriguez
Ok, But I have to display image beside each radio button. Is it possible using Radiobutton list. please see the follwoing code. HtmlInputRadioButton rdb = new HtmlInputRadioButton(); System.Web.UI.WebControls.Image imgasp = new System.Web.UI.WebControls.Image(); for (int i = 0; i < dvForDisplay.Count; i++) { rdb.ID = dvForDisplay[i]["RadioButtonId"].ToString(); rdb.Value = dvForDisplay[i]["PaymentGateway"].ToString(); panelInternational.Controls.Add(rdb); panelInternational.Controls.Add(imgasp); // adding Image beside each radiio button } Thanks
-
Ok, But I have to display image beside each radio button. Is it possible using Radiobutton list. please see the follwoing code. HtmlInputRadioButton rdb = new HtmlInputRadioButton(); System.Web.UI.WebControls.Image imgasp = new System.Web.UI.WebControls.Image(); for (int i = 0; i < dvForDisplay.Count; i++) { rdb.ID = dvForDisplay[i]["RadioButtonId"].ToString(); rdb.Value = dvForDisplay[i]["PaymentGateway"].ToString(); panelInternational.Controls.Add(rdb); panelInternational.Controls.Add(imgasp); // adding Image beside each radiio button } Thanks
-
Ok, But I have to display image beside each radio button. Is it possible using Radiobutton list. please see the follwoing code. HtmlInputRadioButton rdb = new HtmlInputRadioButton(); System.Web.UI.WebControls.Image imgasp = new System.Web.UI.WebControls.Image(); for (int i = 0; i < dvForDisplay.Count; i++) { rdb.ID = dvForDisplay[i]["RadioButtonId"].ToString(); rdb.Value = dvForDisplay[i]["PaymentGateway"].ToString(); panelInternational.Controls.Add(rdb); panelInternational.Controls.Add(imgasp); // adding Image beside each radiio button } Thanks
Im not sure if it is possible, maybe it is, just try it for yourself. After all, a radiobuttonlist is just a grouo of radiobuttons If you use radiobuttonlist you can then add a single validator to this control and validate (on client side) that the users selects one
Alexei Rodriguez