MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Make DropDownList fire a clientside Javascript function?

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> ASPNet
Author Message
John Kotuby



Joined: 08 Aug 2007
Posts: 5

PostPosted: Wed Dec 12, 2007 10:38 pm    Post subject: Make DropDownList fire a clientside Javascript function? Reply with quote

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('');" I
get an error.

Whereas for a simple HTML anchor I can do:
without a problem.

Any ideas?

TIA

Archived from group: microsoft>public>dotnet>framework>aspnet
Back to top
View user's profile Send private message
Scott Roberts



Joined: 15 Nov 2007
Posts: 23

PostPosted: Wed Dec 12, 2007 9:54 pm    Post subject: Re: Make DropDownList fire a clientside Javascript function? Reply with quote

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! Wink

Scott


"John Kotuby" wrote in message @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('');"
> I get an error.
>
> Whereas for a simple HTML anchor I can do:
> > without a problem.
>
> Any ideas?
>
> TIA
>
Back to top
View user's profile Send private message
John Kotuby



Joined: 08 Aug 2007
Posts: 5

PostPosted: Thu Dec 13, 2007 1:24 am    Post subject: Re: Make DropDownList fire a clientside Javascript function? Reply with quote

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" wrote in
message @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! Wink
>
> Scott
>
>
> "John Kotuby" wrote in message
> @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('');"
>> I get an error.
>>
>> Whereas for a simple HTML anchor I can do:
>> >> without a problem.
>>
>> Any ideas?
>>
>> TIA
>>
>
Back to top
View user's profile Send private message
Peter Bromberg [C# MVP]



Joined: 31 Oct 2007
Posts: 22

PostPosted: Wed Dec 12, 2007 11:04 pm    Post subject: Re: Make DropDownList fire a clientside Javascript function? Reply with quote

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


"John Kotuby" wrote:

> 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" wrote in
> message @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! Wink
> >
> > Scott
> >
> >
> > "John Kotuby" wrote in message
> > @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('');"
> >> I get an error.
> >>
> >> Whereas for a simple HTML anchor I can do:
> >> > >> without a problem.
> >>
> >> Any ideas?
> >>
> >> TIA
> >>
> >
>
>
>

Back to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
Setting Checkbox clientside I am trying to set and clear my checkboxes using client-side validation. I have some Javascript to set my checkboxes: