Solved

call javascript from listbox event

Posted on 2004-10-14
7
1,179 Views
Last Modified: 2008-02-01
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?
0
Comment
Question by:Darth_helge
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 15

Accepted Solution

by:
praneetha earned 250 total points
ID: 12310157

<asp:listbox id="ListBox0" runat="server"  onclick="dochange(text)";></asp:listbox>

0
 
LVL 18

Assisted Solution

by:tusharashah
tusharashah earned 250 total points
ID: 12310172
Add following line in your Page_Load event:

ListBox0.Attributes.Add("OnChange", "doChange('text'); return false;");


-tushar
0
 
LVL 6

Expert Comment

by:ryerras
ID: 12311093
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
0
 
LVL 6

Expert Comment

by:ryerras
ID: 12655215
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"
0
 
LVL 5

Author Comment

by:Darth_helge
ID: 12704438
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
0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question