DropDownList Control & Javascript

P

Pierson C

Newbie question:
I have a dropdownlist user control and a radiobutton user control on my
WebForm. I want to simply check the radiobutton when the dropdownlist is
changed.

The OnSelectedIndexChanged method is server side and must post to fire. I
understand I need to use Javascript for the client side interaction, but I am
having trouble connecting the control to the script function.
___________________________________________________________
<script language="javascript">
function changed(cbo){
var rbS = document.getElementById('<%=rbSchool.UniqueID%>');
rbS.Checked = true;

}
</script>
<asp:radiobutton id="rbSchool" runat="server" Text="by School"
GroupName="rbSearch"></asp:radiobutton>
<asp:dropdownlist id="cboSchools" OnSelectedIndexChanged="changed(this)"
Runat="server" Width="208px"></asp:dropdownlist>
______________________________________________________________

It is expecting a server side function: 'ASP.frmPROOF_aspx' does not
contain a definition for 'changed'

Any help would be greatly appreciated!
Pierson
 
K

Ken Cox [Microsoft MVP]

Hi Pierson,

You're trying to mix server-side events and client-side events in a way that
doesn't work. You'll want to use client-side code for this but emit it from
the server-side. Here's the idea:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
cboSchools.Attributes.Add _
("onchange", "document.all.rbSchool.checked=true;return false;")
End Sub

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]
 
P

Pierson C

Ken, That helps immensely!
I am assuming the Attributes method can be used for writing client side
properties associated with most user controls?

The fog has cleared...Many Thanks,
Pierson

Ken Cox said:
Hi Pierson,

You're trying to mix server-side events and client-side events in a way that
doesn't work. You'll want to use client-side code for this but emit it from
the server-side. Here's the idea:

Private Sub Page_Load _
(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
cboSchools.Attributes.Add _
("onchange", "document.all.rbSchool.checked=true;return false;")
End Sub

Let us know if this helps?

Ken
Microsoft MVP [ASP.NET]


Pierson C said:
Newbie question:
I have a dropdownlist user control and a radiobutton user control on my
WebForm. I want to simply check the radiobutton when the dropdownlist is
changed.

The OnSelectedIndexChanged method is server side and must post to fire. I
understand I need to use Javascript for the client side interaction, but I
am
having trouble connecting the control to the script function.
___________________________________________________________
<script language="javascript">
function changed(cbo){
var rbS = document.getElementById('<%=rbSchool.UniqueID%>');
rbS.Checked = true;

}
</script>
<asp:radiobutton id="rbSchool" runat="server" Text="by School"
GroupName="rbSearch"></asp:radiobutton>
<asp:dropdownlist id="cboSchools" OnSelectedIndexChanged="changed(this)"
Runat="server" Width="208px"></asp:dropdownlist>
______________________________________________________________

It is expecting a server side function: 'ASP.frmPROOF_aspx' does not
contain a definition for 'changed'

Any help would be greatly appreciated!
Pierson
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,239
Members
46,827
Latest member
DMUK_Beginner

Latest Threads

Top