Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / December 2007

Tip: Looking for answers? Try searching our database.

Make DropDownList fire a clientside Javascript function?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Kotuby - 12 Dec 2007 22:38 GMT
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
Scott Roberts - 12 Dec 2007 22:54 GMT
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

> Hi all,
>
[quoted text clipped - 13 lines]
>
> TIA
John Kotuby - 13 Dec 2007 01:24 GMT
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.

> John,
>
[quoted text clipped - 21 lines]
>>
>> TIA
Peter Bromberg [C# MVP] - 13 Dec 2007 02:04 GMT
you can always add client-script event handlers to ASP.NET controls via
attributes,  and they will get rendered into the browser as Javascript
--there is rarely a need to author custom  controls in order to do this.
-- Peter
Site: http://www.eggheadcafe.com
UnBlog: http://petesbloggerama.blogspot.com
MetaFinder: http://www.blogmetafinder.com 

> Thanks again Scott,
>
[quoted text clipped - 33 lines]
> >>
> >> TIA

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.