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?
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;
}
}