Make DropDownList fire a clientside Javascript function?

  • Thread starter Thread starter John Kotuby
  • Start date Start date
J

John Kotuby

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.txtUpdate');"
without a problem.

Any ideas?

TIA
 
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
 
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.
 
Back
Top