By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,292 Members | 1,381 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,292 IT Pros & Developers. It's quick & easy.

Make DropDownList fire a clientside Javascript function?

P: n/a
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
Share this Question
Share on Google+
2 Replies


P: n/a
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

P: n/a
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.