Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
594 views
in Technique[技术] by (71.8m points)

c# - 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...