Radio button client events.

  • Thread starter Thread starter Guest
  • Start date Start date
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>
 
JavaScript is Case Sensitive.

So try this:
RadioButton1.Attributes.add("onChange","javascript:alert('onChange
happened'")
 
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.
 
Yes, I see the problem.
Well it seems the easiest solution would be to use an HTML checkbox instead
of the WebControl.

--
I hope this helps,
Steve C. Orr, MCSD, MVP
http://SteveOrr.net
 
Back
Top