Home » Asp.netRSS

AutoPostback in Repeater in UpdatePanel is refreshing the page

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">??&quot;? ???? ?? ?? ??????</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>
 

4 Answers Found

 

Answer 1

hi,

set 

ChildrenAsTriggers="true" in updatepanel

and also try by doing like below

 <Triggers>
 <asp:AsyncPostBackTrigger ControlID="" />
 </Triggers>

 

 

Answer 2

Tried setting ChildrenAsTriggers. Didn't Help.

After all, it is set to true by default, as far as I know.



 

Answer 3

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.

Snippet

<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
        <ContentTemplate>
    

or you can keep the TextBox in an update panel to avoid page  refresh

Snippet

<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.

 

Answer 4

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!


 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter