How to Handle Double Click Event in a ASP.NET ListBox Control

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.


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: