469,950 Members | 2,237 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,950 developers. It's quick & easy.

Make DropDownList fire a clientside Javascript function?

Hi all,

In ASP.NET 2.0 and VB.NET, I am trying to get the OnSelectedIndexChanged
event to fire a Javascript function. There is no OnClientClick event for
that control.

When I try something like:
OnSelectedIndexChanged="javascript:SetOwner('<%= lstOwner.ClientID %>');" I
get an error.

Whereas for a simple HTML anchor I can do:
<a href="javascript:show_calendar('aspnetForm.txtUpda te');"
without a problem.

Any ideas?

TIA
Dec 12 '07 #1
2 10553
John,

I think you're looking for the javascript "onchange" event (which runs in
the browser) not the OnSelectedIndexChanged event (which runs on the
server). Also, don't be afraid to post a little more code! ;)

Scott
"John Kotuby" <Jo********@discussions.microsoft.comwrote in message
news:Ot**************@TK2MSFTNGP06.phx.gbl...
Hi all,

In ASP.NET 2.0 and VB.NET, I am trying to get the OnSelectedIndexChanged
event to fire a Javascript function. There is no OnClientClick event for
that control.

When I try something like:
OnSelectedIndexChanged="javascript:SetOwner('<%= lstOwner.ClientID %>');"
I get an error.

Whereas for a simple HTML anchor I can do:
<a href="javascript:show_calendar('aspnetForm.txtUpda te');"
without a problem.

Any ideas?

TIA
Dec 12 '07 #2
Thanks again Scott,

Sometimes I lose sight of the fact that ASP.NET is simply generating HTML
and I should break out the HTML books to look for the correct clientside
event for the corresponding HTML tags that are rendered and to append the
event to a server control that does not natively support that event. I am
beginning to see the value of custom Server controls that inherit from the
base controls and have developer-added functionality.

Of course, some of the clientside Javascript that ASP.NET generates is
highly inscrutable.

"Scott Roberts" <sr******@no.spam.here-webworks-software.comwrote in
message news:ev**************@TK2MSFTNGP04.phx.gbl...
John,

I think you're looking for the javascript "onchange" event (which runs in
the browser) not the OnSelectedIndexChanged event (which runs on the
server). Also, don't be afraid to post a little more code! ;)

Scott
"John Kotuby" <Jo********@discussions.microsoft.comwrote in message
news:Ot**************@TK2MSFTNGP06.phx.gbl...
>Hi all,

In ASP.NET 2.0 and VB.NET, I am trying to get the OnSelectedIndexChanged
event to fire a Javascript function. There is no OnClientClick event for
that control.

When I try something like:
OnSelectedIndexChanged="javascript:SetOwner('<% = lstOwner.ClientID %>');"
I get an error.

Whereas for a simple HTML anchor I can do:
<a href="javascript:show_calendar('aspnetForm.txtUpda te');"
without a problem.

Any ideas?

TIA

Dec 13 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Federico Moschini [328594] | last post: by
1 post views Thread by Urmal Patel via .NET 247 | last post: by
4 posts views Thread by David | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.