为什么asp.net按钮没有隐藏?

时间:2014-09-18 10:17:58

标签: c# asp.net webforms

我在asp.net表单中遇到了一个奇怪的问题。我试图使按钮不可见/无效但我的代码在任何情况下都不起作用。它仍然可见/活跃。

<asp:Button ID="btnPrintEditedSms" ValidationGroup="Complaints"  runat="server" CssClass="btn btn-success"  
            OnClick="btnPrintEditedSms_Click" Text="Send" />

我正在尝试将代码置于此处,以使其可见或不活动但不起作用,但其他语句无效

 protected void GridViewAllSms_SelectedIndexChanged(object sender, EventArgs e)
    {
        BtnPrintEditedSms.Visible = false; //this doesn't work
        BtnPrintEditedSms.Enabled = false; //this also
        txtComplainant.Visible = true;     //this works

    }

它位于更新面板中:

 <asp:UpdatePanel ID="updGridViewSMS" runat="server" UpdateMode="Conditional">
          <ContentTemplate>
            <label><b>Search By Date Range</b></label>
            <asp:Label ID="lblDateFrom" runat="server" Text="From"></asp:Label>
            <asp:TextBox ID="txtFromDate" runat="server" ></asp:TextBox>                      
            <asp:CalendarExtender ID="CalendarExtenderFromDate" Format="dd/MMM/yyyy" TargetControlID="txtFromDate" runat="server">
            </asp:CalendarExtender>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator9" runat="server" 
                                ControlToValidate="txtFromDate" Display="None" ErrorMessage="" 
                                ForeColor="Red" >
            </asp:RequiredFieldValidator>
            <asp:Label ID="lblDateTo" runat="server" Text="To"></asp:Label>
            <asp:TextBox ID="txtToDate" runat="server"></asp:TextBox>
            <asp:CalendarExtender ID="CalendarExtenderToDate" Format="dd/MMM/yyyy" TargetControlID="txtToDate" runat="server">
            </asp:CalendarExtender>
            <asp:RequiredFieldValidator ID="RequiredFieldValidator10" runat="server" 
                                ControlToValidate="txtToDate" Display="None" ErrorMessage="" 
                                ForeColor="Red" >
            </asp:RequiredFieldValidator>
            <asp:Button ID="btnSearchByDate"  CssClass="btn btn-success" runat="server" Text="Search" 
                        ClientIDMode="Static"  OnClick="btnSearchByDate_Click" />
            &nbsp; 
            <asp:Button ID="btnEdit"  CssClass="btn btn-success" runat="server" Text="Edit" 
                        ClientIDMode="Static" OnClick="btnEdit_Click"  />
</asp:UpdatePanel>

1 个答案:

答案 0 :(得分:0)

试试这个

 protected void GridViewAllSms_SelectedIndexChanged(object sender, EventArgs e)
    {
        BtnPrintEditedSms.Visible = false; //this doesn't work
        BtnPrintEditedSms.Enabled = false; //this also
        txtComplainant.Visible = true;     //this works
        Updatepanel1.Update();
    }

或者如果您不想将更新模式设置为条件,则将其设置为始终为

 <asp:UpdatePanel ID="Updatepanel1" runat="server" UpdateMode="Always">