UpdatePanel中的ListView中的LinkButton会导致完整的回发

时间:2021-10-31 15:05:04

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.

我在UpdatePanel的ListView中有一个LinkButton。我希望按钮(嗯,它们中的任何一个)导致部分回发,但它们正在导致全页回发。

<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 * 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?

也有一些类似的帖子,但是我找不到解决办法!什么好主意吗?

4 个解决方案

#1


38  

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

ASP中的ClientIDMode设置。NET 4允许您指定如何使用ASP。NET为HTML元素生成id属性。

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.

在以前的ASP版本中。NET(即pre 4),默认行为等同于ClientIDMode的自动id设置。然而,默认设置现在是可预测的。

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.

由于脚本管理器期望在. net以前的版本中生成HTML控件的方式,所以需要使用AutoId。

#2


0  

Try adding CommandName, CommandArgument attributes and the OnCommand event handler to your linkbutton like this:

尝试将CommandName、CommandArgument属性和OnCommand事件处理程序添加到您的linkbutton如下:

<asp:LinkButton CommandName='test' CommandArgument='<%# Eval("Title") %>' ID="lnkAddTarget" runat="server" OnCommand="LinkButtonCommandEventHandler" />

Or - adding OnItemCommand handler to the whole ListView.

或-向整个ListView添加OnItemCommand处理程序。

#3


0  

I resolved this problem by setting: ClientIDMode="AutoID" on the page directive of the applicable page like so:<%@ Page Title="" ClientIDMode="AutoID" Language="C#"%>, thus resolving my previous problem of having an ASP linkbutton within a ListView to cause a full postback.

我通过在适用页面的页面指令上设置:ClientIDMode=“AutoID”解决了这个问题,如下所示:<%@页面标题="" " ClientIDMode="AutoID"语言=" c# "%>,从而解决了我以前在ListView中设置ASP链接按钮以导致完整的回发的问题。

However, this may require that any ASP control on the client code (Jquery, Javascript) be referred to by it's full name as it appears in the browser source code (I use Firebug in Firefox to get the names). For example, this Jquery function $("#ContentPlaceHolder1_btnCancelReferCustomer").click(function () { $("#divRefer").hide({ effect: "slide", duration: 200 }); return false; }); was changed to this (please note the asp button name change in selector): $("#ctl00_ContentPlaceHolder1_btnCancelReferCustomer").click(function () { $("#divRefer").hide({ effect: "slide", duration: 200 }); return false; });

但是,这可能需要客户端代码上的任何ASP控件(Jquery、Javascript)在浏览器源代码中出现的时候都可以通过它的全名来引用(我在Firefox中使用Firebug来获取名称)。例如,这个Jquery函数$(“# contentplaceholder1_btncancelreferelreference”)。点击(函数(){ $(" # divRefer ")。隐藏({效果:“幻灯片”,持续时间:200});返回错误;});已更改为这个(请注意选择器中的asp按钮名称更改):$(“#ctl00_ContentPlaceHolder1_btnCancelReferCustomer”)。点击(函数(){ $(" # divRefer ")。隐藏({效果:“幻灯片”,持续时间:200});返回错误;});

#4


0  

I resolved this problem by setting: ClientIDMode="AutoID" on the page directive of the applicable page like so:<%@ Page Title="" ClientIDMode="AutoID" Language="C#"%>

我通过在适用页面的页面指令上设置:ClientIDMode="AutoID"来解决这个问题,如下所示:<%@页面标题="" " ClientIDMode="AutoID"语言=" c# "%>

#1


38  

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

ASP中的ClientIDMode设置。NET 4允许您指定如何使用ASP。NET为HTML元素生成id属性。

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.

在以前的ASP版本中。NET(即pre 4),默认行为等同于ClientIDMode的自动id设置。然而,默认设置现在是可预测的。

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.

由于脚本管理器期望在. net以前的版本中生成HTML控件的方式,所以需要使用AutoId。

#2


0  

Try adding CommandName, CommandArgument attributes and the OnCommand event handler to your linkbutton like this:

尝试将CommandName、CommandArgument属性和OnCommand事件处理程序添加到您的linkbutton如下:

<asp:LinkButton CommandName='test' CommandArgument='<%# Eval("Title") %>' ID="lnkAddTarget" runat="server" OnCommand="LinkButtonCommandEventHandler" />

Or - adding OnItemCommand handler to the whole ListView.

或-向整个ListView添加OnItemCommand处理程序。

#3


0  

I resolved this problem by setting: ClientIDMode="AutoID" on the page directive of the applicable page like so:<%@ Page Title="" ClientIDMode="AutoID" Language="C#"%>, thus resolving my previous problem of having an ASP linkbutton within a ListView to cause a full postback.

我通过在适用页面的页面指令上设置:ClientIDMode=“AutoID”解决了这个问题,如下所示:<%@页面标题="" " ClientIDMode="AutoID"语言=" c# "%>,从而解决了我以前在ListView中设置ASP链接按钮以导致完整的回发的问题。

However, this may require that any ASP control on the client code (Jquery, Javascript) be referred to by it's full name as it appears in the browser source code (I use Firebug in Firefox to get the names). For example, this Jquery function $("#ContentPlaceHolder1_btnCancelReferCustomer").click(function () { $("#divRefer").hide({ effect: "slide", duration: 200 }); return false; }); was changed to this (please note the asp button name change in selector): $("#ctl00_ContentPlaceHolder1_btnCancelReferCustomer").click(function () { $("#divRefer").hide({ effect: "slide", duration: 200 }); return false; });

但是,这可能需要客户端代码上的任何ASP控件(Jquery、Javascript)在浏览器源代码中出现的时候都可以通过它的全名来引用(我在Firefox中使用Firebug来获取名称)。例如,这个Jquery函数$(“# contentplaceholder1_btncancelreferelreference”)。点击(函数(){ $(" # divRefer ")。隐藏({效果:“幻灯片”,持续时间:200});返回错误;});已更改为这个(请注意选择器中的asp按钮名称更改):$(“#ctl00_ContentPlaceHolder1_btnCancelReferCustomer”)。点击(函数(){ $(" # divRefer ")。隐藏({效果:“幻灯片”,持续时间:200});返回错误;});

#4


0  

I resolved this problem by setting: ClientIDMode="AutoID" on the page directive of the applicable page like so:<%@ Page Title="" ClientIDMode="AutoID" Language="C#"%>

我通过在适用页面的页面指令上设置:ClientIDMode="AutoID"来解决这个问题,如下所示:<%@页面标题="" " ClientIDMode="AutoID"语言=" c# "%>