Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

call javascript from listbox event

Posted on 2004-10-14
7
Medium Priority
?
1,191 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 1000 total points
ID: 12310157

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

0
 
LVL 18

Assisted Solution

by:tusharashah
tusharashah earned 1000 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

618 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