I was wondering if anyone else has noticed this. When a DropDownList control is extended with ListSearchExtender, and the DropDownList has the AutoPostBack property set to true, the page loads twice. If you step through the debugger you will see OnInit,
OnPrerender, Page_Load, etc. being called twice.
Does anyone have a workaround to prevent this?
Thanks,
Carl
List Search Extender listseachextender postback twice page load
I'll try to reproduce this to see if I can work out what is going on. Do you have a simple page with just a DropDownList and the extender on it? (No UpdatePanels etc).
This is intereesting. ListSearch only causes double postback when a breakpoint is set. I put together the following code. If you set a breakpoint anywhere in the code-behind, clicking the ListSearch-enabled DropDownList will post back twice. But if you
do not have a breakpoint, it posts back once. It still is behavior that doesn't occur without the ListSearch, but at least it isn't REALLY posting twice. Any idea why this is occurring?
More importantly is the problem of ListSearchExtender not working with CascadingDropDownExtender. This one is easy to see. Just attach both extenders to a DropDownList (like the one in the sample web site) and when you close the form or click on another
page, it throws a javascript null exception. I have documented this at CodePlex as ID# 8887.
I'm guessing that you are seeing multiple postbacks because the SELECT is losing focus several times as the debugger takes focus away, and gives it back -- the extender fires the OnChange when the SELECT loses focus.
With regards to the error with the CascadingDropDownExtender, I have not managed to reproduce this -- I added ListSearchExtenders to each of the lists on the CascadingDropDown example in the toolkit and had no issues -- could you perhaps post a small example
where you are getting an error?
Hi, Damian. Sorry for the delay in getting back to you.
If you download the "How do I?" demo for CascadingDropDown found at
http://www.asp.net/learn/videos/view.aspx?tabid=63&id=77 and add ListSearch to it, you will see the problem. (You will have to update the AjaxToolkit.dll, since that how-to was written prior to ListSearchExtender.) If you add the following lines to Default.aspx
between the opening form tag and the opening table tag that contains the 3 dropdownlists, you will see what I mean:
What are the consequences of removing this call? I assume it would be a memory leak, but is it a leak on the user's machine that goes away when they navigate to a new page, or when they close the browser? Does it increase with each postback? Does it affect
the server? Do the $removeHandler() functions in CascadingDropDownBehavior.js take care of this on behalf of ListSearchExtender (which I assume has something to do with the failure)? etc....
cnelson1
Member
21 Points
43 Posts
ListSearchExtender causing postback twice
Jun 22, 2007 12:54 AM|LINK
I was wondering if anyone else has noticed this. When a DropDownList control is extended with ListSearchExtender, and the DropDownList has the AutoPostBack property set to true, the page loads twice. If you step through the debugger you will see OnInit, OnPrerender, Page_Load, etc. being called twice.
Does anyone have a workaround to prevent this?
Thanks,
Carl
List Search Extender listseachextender postback twice page load
dmehers
Member
142 Points
33 Posts
Re: ListSearchExtender causing postback twice
Jun 22, 2007 04:56 AM|LINK
Hi Carl,
I'll try to reproduce this to see if I can work out what is going on. Do you have a simple page with just a DropDownList and the extender on it? (No UpdatePanels etc).
Thanks,
Damian
http://damianblog.com/
cnelson1
Member
21 Points
43 Posts
Re: ListSearchExtender causing postback twice
Jun 22, 2007 10:21 PM|LINK
Weeeeell....
This is intereesting. ListSearch only causes double postback when a breakpoint is set. I put together the following code. If you set a breakpoint anywhere in the code-behind, clicking the ListSearch-enabled DropDownList will post back twice. But if you do not have a breakpoint, it posts back once. It still is behavior that doesn't occur without the ListSearch, but at least it isn't REALLY posting twice. Any idea why this is occurring?
Thanks,
Carl
.aspx code:
<%
@ Page AutoEventWireup="true" CodeFile="MaskedEditTest.aspx.cs"Culture="auto" Inherits="MaskedEditTest"
Language="C#" Title="MaskedEdit/ListSearch Example" UICulture="auto" %><%
@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><
html xmlns="http://www.w3.org/1999/xhtml"><
head id="Head1" runat="server"> <title>Untitled Page</title></
head><
body> <form id="form1" runat="server"> <div> <ajaxToolkit:ToolkitScriptManager runat="server" ID="ScriptManager1" EnableScriptGlobalization="true" EnableScriptLocalization="true" />DropDownList without ListSearch. Click on
a selection.
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"> <asp:ListItem Text="select one"></asp:ListItem> <asp:ListItem Text="hello"></asp:ListItem> <asp:ListItem Text="goodbye"></asp:ListItem> </asp:DropDownList> <br /> <br /> <asp:Label ID="Label1" runat="server" Text="Postback count: "></asp:Label> <asp:Label ID="Label2" runat="server" Text="0" ></asp:Label> <br /> <br />DropDownList with ListSearch. Click on a
selection.
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true"> <asp:ListItem Text="hello"></asp:ListItem> <asp:ListItem Text="goodbye"></asp:ListItem> </asp:DropDownList> <ajaxToolkit:ListSearchExtender ID="ListSearchExtender1" runat="server" PromptPosition="top" PromptText="Type to search" TargetControlID="DropDownList2"> </ajaxToolkit:ListSearchExtender> <asp:TextBox ID="TextBox1" runat="server" /> <asp:ImageButton ID="ImgBntCalc" runat="server" ImageUrl="~/images/Calendar_scheduleHS.png" CausesValidation="False" /> <ajaxToolkit:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="TextBox1" Mask="99/99/9999" MessageValidatorTip="true" CultureName="en-US" MaskType="Date" DisplayMoney="Left" AcceptNegative="Left" ErrorTooltipEnabled="True" /> <ajaxToolkit:MaskedEditValidator ID="MaskedEditValidator1" runat="server" ControlExtender="MaskedEditExtender1" ControlToValidate="TextBox1" EmptyValueMessage="Date is required" InvalidValueMessage="Date is invalid" Display="Dynamic" TooltipMessage="Input a date" EmptyValueBlurredText="*" InvalidValueBlurredMessage="*" ValidationGroup="MKE" /> <ajaxToolkit:CalendarExtender ID="CalendarExtender1" runat="server" Format="MM/dd/yyyy" TargetControlID="TextBox1" PopupButtonID="ImgBntCalc" /> <br /> <asp:Button runat="server" ID="resetButton" Text="Reset count" OnClick="resetButton_OnClick"/> </div> </form></
body></
html>.cs code:
using
System;using
System.Data;using
System.Configuration;using
System.Web;using
System.Web.Security;using
System.Web.UI;using
System.Web.UI.WebControls;using
System.Web.UI.WebControls.WebParts;using
System.Web.UI.HtmlControls; /// <summary>///
Summary description for MaskedEdit///
</summary>public
partial class MaskedEditTest : Page{
private static int dropDownListPostCount = 0;protected override void OnPreInit(EventArgs e){
base.OnPreInit(e);}
protected override void OnInit(EventArgs e){
base.OnInit(e);}
protected override void OnLoad(EventArgs e){
base.OnLoad(e);}
protected override void OnPreRender(EventArgs e){
base.OnPreRender(e); if (this.IsPostBack){
dropDownListPostCount++;
Label2.Text = dropDownListPostCount.ToString();
}
}
protected void resetButton_OnClick(object sender, EventArgs e){
dropDownListPostCount = -1;
}
}
cnelson1
Member
21 Points
43 Posts
Re: ListSearchExtender causing postback twice
Jun 22, 2007 10:52 PM|LINK
More importantly is the problem of ListSearchExtender not working with CascadingDropDownExtender. This one is easy to see. Just attach both extenders to a DropDownList (like the one in the sample web site) and when you close the form or click on another page, it throws a javascript null exception. I have documented this at CodePlex as ID# 8887.
Thanks,
Carl
dmehers
Member
142 Points
33 Posts
Re: ListSearchExtender causing postback twice
Jun 28, 2007 06:52 PM|LINK
Hi Carl,
I'm guessing that you are seeing multiple postbacks because the SELECT is losing focus several times as the debugger takes focus away, and gives it back -- the extender fires the OnChange when the SELECT loses focus.
With regards to the error with the CascadingDropDownExtender, I have not managed to reproduce this -- I added ListSearchExtenders to each of the lists on the CascadingDropDown example in the toolkit and had no issues -- could you perhaps post a small example where you are getting an error?
Thanks,
Damian
http://damianblog.com/
cnelson1
Member
21 Points
43 Posts
Re: ListSearchExtender causing postback twice
Jul 13, 2007 06:56 PM|LINK
Hi, Damian. Sorry for the delay in getting back to you.
If you download the "How do I?" demo for CascadingDropDown found at http://www.asp.net/learn/videos/view.aspx?tabid=63&id=77 and add ListSearch to it, you will see the problem. (You will have to update the AjaxToolkit.dll, since that how-to was written prior to ListSearchExtender.) If you add the following lines to Default.aspx between the opening form tag and the opening table tag that contains the 3 dropdownlists, you will see what I mean:
<ajaxToolkit:ListSearchExtender ID="ListSearchExtender1"
runat="server" TargetControlID="DropDownList1">
</ajaxToolkit:ListSearchExtender>
<ajaxToolkit:ListSearchExtender ID="ListSearchExtender2"
runat="server" TargetControlID="DropDownList2">
</ajaxToolkit:ListSearchExtender>
<ajaxToolkit:ListSearchExtender ID="ListSearchExtender3"
runat="server" TargetControlID="DropDownList3">
</ajaxToolkit:ListSearchExtender>
It will run fine, but when you close the page, or try to go to a different URL, you will get the following message:
Sys.InvalidOperationException: Handler was not added through the Sys.UI.DomEvent.addHandler method.
I would really like to use these two extenders together. Could you look into this?
Thanks,
Carl
cnelson1
Member
21 Points
43 Posts
Re: ListSearchExtender causing postback twice
Jul 19, 2007 07:35 PM|LINK
I was able to get ListSearch and CascadingDropDown to work together by removing this line:
$clearHandlers(this.get_element());
from the dispose function in ListSearchBehavior.js. I tried replacing it with this code:
var element = this.get_element();$removeHandler(element,
'focus', this._onFocus); $removeHandler(element, 'blur', this._onBlur);$removeHandler(element,
'keydown', this._onKeyDown); $removeHandler(element, 'keyup', this._onKeyUp);$removeHandler(element,
'keypress', this._onKeyPress);but it still failed.
What are the consequences of removing this call? I assume it would be a memory leak, but is it a leak on the user's machine that goes away when they navigate to a new page, or when they close the browser? Does it increase with each postback? Does it affect the server? Do the $removeHandler() functions in CascadingDropDownBehavior.js take care of this on behalf of ListSearchExtender (which I assume has something to do with the failure)? etc....
Thanks,
Carl
ListSearch CascadingDropDown removeHandler clearHandler InvalidOperationException addHandler
cnelson1
Member
21 Points
43 Posts
Re: ListSearchExtender causing postback twice
Jul 25, 2007 04:45 PM|LINK
anyone?
dmehers
Member
142 Points
33 Posts
Re: ListSearchExtender causing postback twice
Jul 26, 2007 07:31 AM|LINK
I'll be looking into this in the next day or so and will do my best to get a fix into the next toolkit release.
Regards,
Damian
http://damianblog.com/
cnelson1
Member
21 Points
43 Posts
Re: ListSearchExtender causing postback twice
Jul 26, 2007 02:12 PM|LINK
Great!
Thanks, Damian.