Solved

call javascript from listbox event

Posted on 2004-10-14
7
1,175 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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
"Emulate" TAB key when press Enter Key 3 66
FInd Image Control Gridview 3 35
Finding the IIS version 5 37
Connect Gridview column to Textbox in C# 2 35
This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

713 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