Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Question
Tuesday, August 31, 2010 6:47 AM
Here's quite a weird problem:
I've got a TextBox with AutoPostBack="true" and OnTextChanged property set.
The textbox is located inside a Repeater, which in turn is located inside an UpdatePanel.
Problem is - whenever the TextBox postsback, the whole page gets reloaded, instead of the UpdatePanel only.
Here's how the thing looks:
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Repeater ID="itemsRepeater" runat="server">
<HeaderTemplate>
<ul class="lstProducts">
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:TextBox AutoPostBack="true" OnTextChanged="whatever_Click" runat="server" />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</div>
</ContentTemplate>
</asp:UpdatePanel>
Interesting thing is, if I take the TextBox out of the repeater, it refreshes only the UpdatePanel.
So is if I put a Button inside the repeater - only the UpdatePanel gets refreshed.
But whenver I place an AutoPostBack-ing control inside the Repeater, the whole page gets refreshed.
Any help would be welcomed,
Thanks
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Repeater ID="itemsRepeater" runat="server">
<HeaderTemplate>
<ul class="lstProducts">
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:TextBox AutoPostBack="true" OnTextChanged="whatever_Click" runat="server" />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
<div class="sumofproducts">
<span class="amount-price">
<asp:Label ID="totlaPriceLabel" runat="server" />
₪</span> <span class="title-price">סה"כ מחיר של כל מוצרים</span>
</div>
</ContentTemplate>
<asp:UpdatePanel runat="server">
<ContentTemplate>
<asp:Repeater ID="itemsRepeater" runat="server">
<HeaderTemplate>
<ul class="lstProducts">
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:TextBox AutoPostBack="true" OnTextChanged="whatever_Click" runat="server" />
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
</ContentTemplate>
</asp:UpdatePanel>
</asp:UpdatePanel>
All replies (6)
Tuesday, August 31, 2010 8:47 AM ✅Answered
It seems like the TextBox is causing the full postback.
you can try it in two different ways. not sure which one works as I haven't tested these approaches.
set update mode to Conditional for the repeater instead of leaving it to update always as long as it does not affect your current code.
<title>Snippet</title>
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
<ContentTemplate>
or you can keep the TextBox in an update panel to avoid page refresh
<title>Snippet</title>
<ItemTemplate>
<li>
<asp:UpdatePanel ID="updpnlTextBox" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
<ContentTemplate>
<asp:TextBox ID="TextBox1" AutoPostBack="true" OnTextChanged="whatever_Click" runat="server" />
</ContentTemplate>
</asp:UpdatePanel>
</li>
</ItemTemplate>
you can also try setting ChildrenAsTriggers to false in the repeater but if you are changing the repeater content on textbox text changed event, Those will not work.
correct me if I had understood any thing wrong.
Tuesday, August 31, 2010 8:07 AM
hi,
set
ChildrenAsTriggers="true" in updatepanel
and also try by doing like below
<Triggers>
**<asp:AsyncPostBackTrigger ControlID="" />
** </Triggers>
Tuesday, August 31, 2010 8:31 AM
Tried setting ChildrenAsTriggers. Didn't Help.
After all, it is set to true by default, as far as I know.
Tuesday, August 31, 2010 9:27 AM
Thanks for the help sansan.
You were not 100% right, but you led me to the answer.
As it seems, when inside a repeater, the ChildrenAsTrigger doesn't work, so you have to specify the Trigger manually.
What I did is this:
<asp:Repeater ID="itemsRepeater" runat="server">
<HeaderTemplate>
<ul class="lstProducts">
</HeaderTemplate>
<ItemTemplate>
<li>
<asp:UpdatePanel ID="updatePanel" runat="server">
<ContentTemplate>
<asp:TextBox ID="whatever" runat="server" AutoPostBack="true" OnTextChanged="whatever_Click" />
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="whatever" EventName="TextChanged" />
</Triggers>
</asp:UpdatePanel>
</li>
</ItemTemplate>
<FooterTemplate>
</ul>
</FooterTemplate>
</asp:Repeater>
And it worked as a charm!
Tuesday, January 11, 2011 12:50 PM
Little bit old post, and older answer too! But I have a better solution for this issue (I don't know why it don't work with a simple update panel yet).
You can rewrite your code like the original one, but redifining the ItemDataBound event in the repeater control. It would look like this:
**protected void itemsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
yourScriptManager.RegisterAsyncPostBackControl((e.Item.FindControl("whatever") as TextBox));
}
**
The idea is that you must assign the postback to the scriptmanager
Tuesday, October 18, 2011 9:51 AM
Much better !
Verry nice, thank you !