Wednesday, March 21, 2012

DropDownExtender causes double postback

Hi,

Is it a known issue that the DropDownExtender causes a double postback? When this control is removed the problem doesn't happen. Worse still it gets into if(isPostBack)... Is there a work around for this?

Best regards,

Sean

Try set autopostback = false on the DropDown control.


The DropDownExtender does not have an autopostback field. I am talking about the DropDownExtender that comes with the Atlas toolkit. Also, I forgot to mention that this problem only happens in FireFox. The double postback does not happen in IE.


Hi Seeeaan,

DropDownExtender itself won't cause any postbacks. Just like the ModalPopupExtender, when drop the the element which is associated with DropDownExtender will show a panel. When click on the control inside the panel, it may cause a postback. But all this based on the clicked control instead of DropDownExtender. So would you please have a check on the controls inside the Panel. Here is a sample.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void OnSelect(object sender, EventArgs e) { lblSelection.Text = "You selected <b>" + ((LinkButton)sender).Text + "</b>."; }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Label ID="TextLabel" runat="server" Text="Select your favorite exotic ice-cream flavor" Style="display: block; width: 300px; padding:2px; padding-right: 50px; font-family: Tahoma; font-size: 11px;" /> <asp:Panel ID="DropPanel" runat="server" CssClass="ContextMenuPanel" Style="display :none; visibility: hidden;"> <asp:LinkButton runat="server" ID="Option1" Text="Mocha Blast" CssClass="ContextMenuItem" OnClick="OnSelect" /> <asp:LinkButton runat="server" ID="Option2" Text="Java Cyclone" CssClass="ContextMenuItem" OnClick="OnSelect" /> <asp:LinkButton runat="server" ID="Option3" Text="Dry Fruit" CssClass="ContextMenuItem" OnClick="OnSelect" /> </asp:Panel> <ajaxToolkit:DropDownExtender runat="server" ID="DDE" TargetControlID="TextLabel" DropDownControlID="DropPanel" /> <asp:UpdatePanel id="Update" runat="server"> <ContentTemplate> <asp:Label id="lblSelection" runat="server" Style="padding: 5px;" /> </ContentTemplate> <Triggers> <asp:AsyncPostBackTrigger ControlID="Option1" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="Option2" EventName="Click" /> <asp:AsyncPostBackTrigger ControlID="Option3" EventName="Click" /> </Triggers> </asp:UpdatePanel> </form></body></html>

To find out whether a double postback occurred, we suggest that you should use a debugging tool such as Web Developer Helper, Fiddler etc.

I hope this help.

Best regards,

Jonathan


Hi Jonathan,

Ok, I shouldn't be calling it a postback. As I mentioned this problems seems to occur on Firefox but not in IE. What I meant to say is that Page_Load is triggered twice. I've set a breakpoint at if(!ispostback) when the page first loads and the breakpoint is triggered twice.

If you try this using the DropDdownExtender sample that comes with the toolkit, you will see what I mean. Again, this problem occurs with Firefox only.

Best regards,

Sean


Hi Seeeaan,

1protected int i = 0;2protected void OnSelect(object sender, EventArgs e)3 {4 lblSelection.Text ="You selected <b>" + ((LinkButton) sender).Text +"</b>.";5 }6protected void Page_Load(object sender, EventArgs e)7 {8 i++;9if (!IsPostBack) {10 i++;11 }12 }

I have added breakpoints at line 8 and 9 and then had a test(The test sample is the sample contains inside Ajax Control Toolkit). My test shows Page_Load only was fired one time but not twice.

My system environments: Windows 2003 + Visual Studio 2005 + Asp.NET 2.0 Ajax Extensions V1.0 + Ajax Control Toolkit V10618.

Test browsers: IE7 + Firefox2.0.

In your situation, If there is an asynchronous postback (some Ajax Controls,for example: AutoComplete), it will cause Page_Load is called twice.

So in brief, my suggestion is check your system environments and your code.

I hope this help.

Best regards,

Jonathan


Hmm... could be something different with my system environment. However, this problem has disappeared in the latest Control Toolkit released a few days ago.

Thanks for spending the time to have a look at this problem.

Cheers,

Sean

No comments:

Post a Comment