Tuesday, October 6, 2009

Double click event for asp.net List Box control

If your requirement is to redirect or other functionalities to be done on double clicking of list box control then here is the solution.
Write following JavaScript method.
function m_lbFallowUp_DoubleClick() {
/* we will change value of this hidden field so that in
page load event we can identify event.
*/
var list = document.getElementById('ctl00_ctl00_ContentPlaceHolder2_m_tpFallowUp_m_lbFallowUp');
for (var i = 0; i < list.options.length; i++) {
if (list.options[i].selected == true) {
document.forms[0].ListBox1Hidden.value = "doubleclicked";
document.forms[0].submit();
}
}
}
place this code in aspx markup
asp:ListBox ID="m_lbFallowUp" Width="400px" Height ="100px" runat="server" ondblclick="m_lbFallowUp_DoubleClick()" asp:ListBox
input type="hidden" name="ListBox1Hidden"
Inside code behind place this code
protected void Page_Load(object sender, EventArgs e)
{
if (Request.Params["ListBox1Hidden"] != null && (string)Request.Params["ListBox1Hidden"] == "doubleclicked")
{
if (m_lbFallowUp.SelectedItem != null)
{
int fallowUpId = Convert.ToInt32(m_lbFallowUp.SelectedItem.Value);
Response.Redirect("~\\Forms\\CreateFallowUp.aspx?SuggestionId=" + suggestionId + "&FallowUpId=" + fallowUpId );
}
}
}

No comments:

Post a Comment