Solved

call javascript from listbox event

Posted on 2004-10-14
7
1,171 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
7 Comments
 
LVL 15

Accepted Solution

by:
praneetha earned 250 total points
Comment Utility

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

0
 
LVL 18

Assisted Solution

by:tusharashah
tusharashah earned 250 total points
Comment Utility
Add following line in your Page_Load event:

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


-tushar
0
 
LVL 6

Expert Comment

by:ryerras
Comment Utility
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
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now