Link to home
Start Free TrialLog in
Avatar of Darth_helge
Darth_helge

asked on

call javascript from listbox event

Hi everyone!

I have this:

<asp:listbox id="ListBox0" runat="server" ></asp:listbox>

I want the onSelectedIndexChanged to call a javascript function called "doChange(text)"

(I can solve the problem with an AutoPostBack to the server, but then the whole page reloads, and this takes a while since i have big pictures and two <iframe> on it, and I don't want the page to reload)

How do I do this?
ASKER CERTIFIED SOLUTION
Avatar of praneetha
praneetha

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of ryerras
ryerras

Tushar's answer is correct. Asp.NET drop downlist or Listbox renders as SELECT html element when the web page is displayed. So, whenever you want to handle any client side event, look for the client side event for the corresponding html element events. You can either add the event in the aspx page itself or in code behind. For your case,

you can say,
<asp:listbox id="ListBox0" runat="server"  onChange="dochange(text)";></asp:listbox>
or
ListBox0.Attributes.Add("OnChange", "doChange('text'); return false;");

 when you are adding onChange event in the aspx page, you wouldnt find that in the intellisense, since its only client side event, server controls only show the events which can be handled in the server side only. So, since onChange is not handled on the server, vs.net wouldnt bother to show it in the intellisense, since at that moment, the control is only a server control, not a html control

Thought I would add something extra to what the previous guys said
I think tushar's answer is correct. User is talking about a client side alternative for SelectedIndexChanged, the client side event for this is "onChange" not "onClick"
Avatar of Darth_helge

ASKER

hello everyone.

im so sorry for not accepting any answers. it's just all the emails sent to me from this website was stopped by our new spam filter at work. i will see to it that your emails will slip through the filter hereafter