Click event of a list box control

S

Scott

I have an asp.net page where I need to fill a grid when the user clicks
items in a list box control on the same page. There does not seem to be a
click event and the "onselectedindexchanged" item does not fire when the
user clicks on the items in the listbox.

Scott
 
A

Alessandro Zifiglio

hi scott,
Make sure you set the AutoPostBack property of the listbox to true,
otherwise it wont autopostback ;)
 
J

Jeffrey Tan[MSFT]

Hi Scott,

The Click and SelectedIndexChanged are the server side events which can
fire when post back.
When you click items, the page will not postback to the server side, no
server side event will fire.
So just as Alessandro said, you should set the ListBox's AutoPostBack
property to true.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Scott,

Thanks for your feedback.
The .Net listbox web server control does not encapsulate the double click
event(Actually, all the web controls do not encapsulate this event).
So we had to use the client script ondblclick event.
Sample code like this:
<script language="javascript">
function showitem()
{

alert(document.Form1["ListBox1"].options[document.Form1["ListBox1"].selected
Index].text );
}
</script>

private void Page_Load(object sender, System.EventArgs e)
{
ListBox lb=(ListBox)this.FindControl("ListBox1");
lb.Attributes.Add("OnDblClick","showitem()");
}

Note: The showitem() function is client side javascript code.

In the code above, I add the OnDblClick event handler in Page's Load event.
If you want to encapsulate this function into your ListBox server control,
you can override its Render method and add the OnDblClick event handler,
then render out your client side javascript code(i.e. showitem() function)

If you still have anything unclear, please feel free to let me know. I am
glad to work with you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,085
Messages
2,570,597
Members
47,218
Latest member
GracieDebo

Latest Threads

Top