ASP UpdatePanel在ContentPage中使用时不起作用

本文关键字:不起作用 UpdatePanel ContentPage ASP | 更新日期: 2023-09-27 17:52:16

我的代码在正常的web表单中使用时工作良好。但是当我在使用母版的网页中使用它时,它不起作用。


页眉:~/Manager/basmanager .master


和一些嵌套的母版页:master> Pages。master> basmanager .master


ASP

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
      <Triggers>
         <asp:AsyncPostBackTrigger EventName="Click"
              ControlID="btnUpdateEditPage" />
      </Triggers>
      <ContentTemplate>
         <asp:Label ID="lblTest" runat="server" Text="Label"></asp:Label>
      </ContentTemplate>
   </asp:UpdatePanel>
<asp:Button ID="btnUpdateEditPage" CssClass="btnUpdateEditPage" runat="server"  
     Text="Button" OnClick="btnUpdateEditPage_Click" />
c#

protected void btnUpdateEditPage_Click(object sender, EventArgs e)
{
   lblTest.Text += "**";
}

ASP UpdatePanel在ContentPage中使用时不起作用

请按以下步骤操作:

1- Add UpdatePanel1.Update();例如:

protected void btnUpdateEditPage_Click(object sender, EventArgs e)
{
   lblTest.Text += "**";
   UpdatePanel1.Update();
   //Your UpdatePanel should be UpdateMode="Conditional" as what you have now..
}

2-把按钮放在更新面板

3-删除触发器不触发post返回,所以你的代码必须是这样的:

 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
   <asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional"> 
      <ContentTemplate>
         <asp:Label ID="lblTest" runat="server" Text="Label"></asp:Label>
         <asp:Button ID="btnUpdateEditPage" CssClass="btnUpdateEditPage" runat="server"  
                Text="Button" OnClick="btnUpdateEditPage_Click" />
      </ContentTemplate>
   </asp:UpdatePanel>

将按钮放置在UpdatePanel中

SOLVED.

I change

<form id="form1" runat="server" action="post">

<form id="form1" runat="server">

,我的问题解决了。但是为什么呢? !