Make DropDownList fire a clientside Javascript function?

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
 
S

Scott Roberts

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
 
J

John Kotuby

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.
 

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

Top