Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to get radiobutton value inside a button click event. [modified]

How to get radiobutton value inside a button click event. [modified]

Scheduled Pinned Locked Moved ASP.NET
javascripthelptutorial
7 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    chakran
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • C chakran

      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

      A Offline
      A Offline
      AlexeiXX3
      wrote on last edited by
      #2

      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

      C 1 Reply Last reply
      0
      • A AlexeiXX3

        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

        C Offline
        C Offline
        chakran
        wrote on last edited by
        #3

        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

        A 1 Reply Last reply
        0
        • C chakran

          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

          A Offline
          A Offline
          AlexeiXX3
          wrote on last edited by
          #4
              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

          C 1 Reply Last reply
          0
          • A AlexeiXX3
                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

            C Offline
            C Offline
            chakran
            wrote on last edited by
            #5

            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

            C A 2 Replies Last reply
            0
            • C chakran

              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

              C Offline
              C Offline
              chakran
              wrote on last edited by
              #6

              Can you tell me how to validate on client side? If I click radio button have to call javascript function. Thanks,

              1 Reply Last reply
              0
              • C chakran

                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

                A Offline
                A Offline
                AlexeiXX3
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups