This article describes how to handle double click event in ASP.NET List control.
Generally, you cannot handle Server side double click event in a ASP.NET List control. But it can be achieved by some workaround methods.
The following steps explain a work around solution:
1. Add a button control and hide it using styles eg: 2. Add the following code in Page_Load Event if(!PostBack) { String postBackReferenceForListBox = this.Page.GetPostBackClientEvent(btnForListBoxDoubleClick, "dblClickfromHiddenButton"); ListBox1.Attributes.Add("ondblclick", postBackReferenceForListBox); }
3. Write the following code to handle Double Click event in the button’s click event private void btnForListBoxDoubleClick_ServerClick(object sender, System.EventArgs e) { string argument = Request.Params["__EVENTARGUMENT"].Trim(); if(argument == "dblClickfromHiddenButton") { // logic to process the selected item from listbox goes here } }
The function GetPostBackClientEvent in step 2 obtains a reference to a client-side script function that causes, when invoked, a server postback to the form.
|
| Author: miriam 02 Nov 2009 | Member Level: Bronze Points : 2 |
don't work for me the erorr I get when doubleClick:
Invalid postback or callback argument. Event validation is enabled using in configuration or <%@ Page EnableEventValidation="true" %> in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation
|