Radio button client events.

G

Guest

How do I create client events for a radio button?
Do I have to switch to HTML controls?
The code below doesn't work.

<body MS_POSITIONING="FlowLayout">
<script runat="server">
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
RadioButton1.Attributes.add("onchange","javascript:alert('Onchanged
happened'")
end sub
</script>
<form id="Form1" method="post" runat="server">
<asp:RadioButton id="RadioButton1" runat="server" GroupName="sort"
Text="Ascending"></asp:RadioButton>
<asp:RadioButton id="RadioButton2" runat="server" GroupName="sort"
Text="Descending"></asp:RadioButton>
</form>
</body>
 
S

Steve C. Orr [MVP, MCSD]

JavaScript is Case Sensitive.

So try this:
RadioButton1.Attributes.add("onChange","javascript:alert('onChange
happened'")
 
G

Guest

No it didn't do anything. Here is the output
<span onChange="javascript:alert('Onchanged happened'"><input
id="RadioButton1" type="radio" name="sort" value="RadioButton1" /><label
for="RadioButton1">Ascending</label></span>
<input id="RadioButton2" type="radio" name="sort" value="RadioButton2"
/><label for="RadioButton2">Descending</label>
The onChange event is in the wrong place.
 
S

Steve C. Orr [MVP, MCSD]

Yes, I see the problem.
Well it seems the easiest solution would be to use an HTML checkbox instead
of the WebControl.
 

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

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top