Asp.net 对更新面板感到困惑

Asp.net 对更新面板感到困惑,asp.net,updatepanel,Asp.net,Updatepanel,在我的表单中,我有一个标签和按钮控件。 默认情况下,标签是可见的。当用户单击按钮时,我已将标签设置为可见false。 对于simple button,它可以工作,但当我向button添加updatePanel时,事件被触发,但标签不可见false。试一试,谁能告诉我为什么会发生这种情况,以及解决办法 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp

在我的表单中,我有一个标签和按钮控件。 默认情况下,标签是可见的。当用户单击按钮时,我已将标签设置为可见false。 对于simple button,它可以工作,但当我向button添加updatePanel时,事件被触发,但标签不可见false。试一试,谁能告诉我为什么会发生这种情况,以及解决办法

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>    

<asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload>       
<asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>     
<asp:UpdatePanel ID="up" runat ="server" >
  <ContentTemplate >
    <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
  </ContentTemplate>
</asp:UpdatePanel>

protected void Button1_Click(object sender, EventArgs e)
{
    Response.Write("hello");
    Label1.Visible = false;
}

受保护的无效按钮1\u单击(对象发送者,事件参数e)
{
回复。写下(“你好”);
标签1.可见=假;
}

从外观上看,您还需要在更新面板中包装标签

试一试



更新面板将更新页面的某个部分。您的标签未包含在updatepanel中,因此永远不会使用新值进行更新。

我建议您只使用updatepanel包装标签,并将UpdateMode设置为“有条件”


问候

<asp:fileupload ID="Fileupload1" runat="server"></asp:fileupload> 
<asp:UpdatePanel ID="up" runat ="server" >    
    <ContentTemplate>  
        <asp:Label ID="Label1" runat="server" Text="Label" ></asp:Label>     
        <asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
    </ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="up" runat ="server" UpdateMode="Coditional" >    
    <ContentTemplate>  
        <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>                 
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="Button1" />
    </Triggers>
</asp:UpdatePanel>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />