Nygter
asked on
Listbox with doubleclick event (one-click event fires BEFORE double-click event, messing it up)
Greetings..
I've successfully made a doubleclick event on a listbox, but with one annoying issue i cannot bare with:
The "single-click" event fires first (when i select an listitem) so that the double-click event doesn't work until the second time i double-click the listitem. See code below.
I've successfully made a doubleclick event on a listbox, but with one annoying issue i cannot bare with:
The "single-click" event fires first (when i select an listitem) so that the double-click event doesn't work until the second time i double-click the listitem. See code below.
/// CODE I PAGE LOAD.
lbAllTemplateTasks.Attributes.Add("ondblclick", ClientScript.GetPostBackEventReference(lbAllTemplateTasks, "addthis"));
if (Request["__EVENTARGUMENT"] != null && Request["__EVENTARGUMENT"] == "addthis")
{
if (lbAllTemplateTasks.SelectedIndex > -1)
{
TemplateTask tt = TemplateTask.TryFind(Convert.ToInt32(lbAllTemplateTasks.SelectedValue));
Stage stage = Stage.Find(Convert.ToInt32(ddlSelectStage.SelectedValue));
stage.TemplateTaskList.Add(tt);
stage.SaveAndFlush();
}
lbAllTemplateTasks.DataBind();
lbThisTemplateTasks.DataBind();
upnlAllTemplateTasks.Update();
upnlThisTemplateTasks.Update();
}
You can disable the onclick event by using the -= syntax to remove the handler and reapplying it when it is ok for it to fire
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Aah.. thank you for this Apresto !.. Most useful !..
Since i have to use the eventhandling many places i've made my own listboxcontrol which extends Listbox and implements IPostBackEventHandler.
Only issue is that it fires on the _CLICK_ event.. not the _DOUBLE_CLICK_.. weird..
It works marvelously, but.. it does the moving on the click event, not the doubleclick :)
Care to take a quick look ?
Since i have to use the eventhandling many places i've made my own listboxcontrol which extends Listbox and implements IPostBackEventHandler.
Only issue is that it fires on the _CLICK_ event.. not the _DOUBLE_CLICK_.. weird..
It works marvelously, but.. it does the moving on the click event, not the doubleclick :)
Care to take a quick look ?
LISTBOXCONTROL :
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.Design.WebControls;
namespace Induct_Ctl
{
public class InductListBox : ListBox,IPostBackEventHandler
{
public event EventHandler DoubleClick;
protected virtual void OnDoubleClick(EventArgs e)
{
if(DoubleClick != null)
{
DoubleClick(this, e);
}
}
public void RaisePostBackEvent(string navigateUrl)
{
this.OnDoubleClick(System.EventArgs.Empty);
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e); this.Attributes.Add("ondblclick", "javascript: " + Page.GetPostBackEventReference(this));
}
}
}
Usage :
protected void lnkSetTemplateTask_Click(object sender, ImageClickEventArgs e)
{
if (lbAllTemplateTasks.SelectedIndex > -1)
{
addTemplateTask();
}
}
<Induct:InductListBox ID="lbThisTemplateTasks" runat="server"
DataSourceID="odsExistingTemplateTasks" DataTextField="Title" DataValueField="Id"
Height="120px" Width="210px" AutoPostBack="True"
onselectedindexchanged="lbThisTemplateTasks_SelectedIndexChanged" OnDoubleClick="lbThisTemplateTasks_DoubleClick"
/>