Access HTML Control from code-behind

F

fxs

Hello,

I have the following controls on an aspx page: 2 html radio button
controls, 1 asp:label control and 1 asp:button control....
<INPUT id="rdo1" type="radio" name="grp1" onClick="clientsidecode();">
<INPUT id="rdo2" type="radio" name="grp1" checked
onclick="clientsidecode();">
<asp:Label id="Label1" runat="server">Label</asp:Label>
<asp:Button id="Button1" runat="server" Text="Button"></asp:Button>

I'm confused as to whether it is possible at all, and if possible, how I
would do the following:

(1) Access the values of the HTML radio buttons in the Button1_Click()
function in the code behind; and display the value on the asp:Label on the
page.

(2) on click of the radio button (in the javascript function
clientsidecode()), write something to the asp:Label control.

Is this possible? How would I do this? Thanks in advance,

Fxs.






One ASP:Label control
 
B

billmiami2

To access the values of the radio buttons, add runat=server to the two
radio buttons and declare them in your codebehind as in

Protected WithEvents rdo1, rdo2 as HtmlInputRadioButton

or in C#

protected HtmlInputRadioButton rdo1, rdo2;

The values rdo1.Checked and rdo2.Checked should now be available to you
in your Button1_Click() event handler.

To do the client side code, add a client side event handler to both
radio bottons for the change event

onchange="document.getElementById('label1').innerHTML+=this.checked;"

and you should have what you want.

Bill E.
Hollywood, FL
 
S

Steve C. Orr [MVP, MCSD]

To access the radio buttons from server side code, you must add the
runat=server attribute to their definitions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top