Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LinkButton in ListView in UpdatePanel causes full postback

I have a LinkButton in a ListView in an UpdatePanel. I would like the button (well, any of them) to cause a partial postback, but they are causing a full page postback.

<asp:UpdatePanel ID="upOutcomes" UpdateMode="Conditional" runat="server">
  <ContentTemplate>
      <asp:ListView ID="lvTargets" runat="server" onitemdatabound="lvTargets_ItemDataBound">
        <ItemTemplate>
          <asp:LinkButton ID="lnkAddTarget" CssClass="lo" Text='<%# Eval("Title") + " <b>" + Eval("Level") + Eval("SubLevel") + "</b>" %>' runat="server"></asp:LinkButton>
        </ItemTemplate>
      </asp:ListView>
  </ContentTemplate>
</asp:UpdatePanel>

I found another post on stackoverflow which suggested adding this:

protected void lvTargets_ItemDataBound(object sender, ListViewItemEventArgs e) {
  var lb = e.Item.FindControl("lnkAddTarget") as LinkButton;
  tsm.RegisterAsyncPostBackControl(lb);  // ToolkitScriptManager
}

It hasn't made a difference...

There are a few other similar posts too, but I can't find a solution! Any ideas?

like image 857
James Avatar asked Apr 13 '11 16:04

James


People also ask

How do you do a full postback on UpdatePanel?

You can use the Triggers property of the UpdatePanel to register actions that trigger a full postback. Add a PostBackTrigger object to that property, containig the ControlID of the control which needs to trigger a full postback.

What happens when a button placed in the UpdatePanel control is clicked?

The UpdatePanel control contains a Button control that refreshes the content inside the panel when you click it. By default, the ChildrenAsTriggers property is true. Therefore, the Button control acts as an asynchronous postback control.

How does UpdatePanel work in asp net?

UpdatePanel controls are a central part of AJAX functionality in ASP.NET. They are used with the ScriptManager control to enable partial-page rendering. Partial-page rendering reduces the need for synchronous postbacks and complete page updates when only part of the page has to be updated.


2 Answers

The ClientIDMode setting in ASP.NET 4 lets you specify how ASP.NET generates the id attribute for HTML elements.

In previous versions of ASP.NET (i.e. pre 4), the default behavior was equivalent to the AutoID setting of ClientIDMode. However, the default setting is now Predictable.

Read Microsoft Article

AutoId is required for this because of the way the script manager expects the HTML controls to be generated in previous versions of .NET.

like image 77
Steve Parker Avatar answered Oct 18 '22 23:10

Steve Parker


I resolved this problem by setting: ClientIDMode="AutoID" on the page directive of the applicable page like so:

<%@ Page Title="" ClientIDMode="AutoID" Language="C#"%>

This is working fine.

like image 1
Prithivirajan Avatar answered Oct 18 '22 23:10

Prithivirajan