代码之家  ›  专栏  ›  技术社区  ›  Afshar Mohebi

AsyncPostBackTrigger禁用按钮

  •  1
  • Afshar Mohebi  · 技术社区  · 15 年前

    我有一个简单的更新面板和一个按钮。我在updatepanel中将该按钮作为AsyncPostBackTrigger引入。updatepanel本身工作正常,但按钮不正常。无论何时单击按钮,其单击处理程序都不会像根本不单击按钮那样运行!

    为什么按钮不起作用,如何固定?


    更新: 标记如下:

                <asp:UpdatePanel ID="upGridView" runat="server" UpdateMode="Conditional">
                <ContentTemplate>
                    <asp:GridView ID="grdList" SkinID="SimpleGridView" DataKeyNames="Key" runat="server"
                        AllowPaging="True" PageSize="15" AutoGenerateColumns="False" Caption="<%$ Resources: CommonResources, grdListCaption %>"
                        EmptyDataText="<%$ Resources: CommonResources, grdListEmptyDataText %>" OnRowEditing="grdList_RowEditing"
                        OnPageIndexChanging="grdList_PageIndexChanging" OnRowCreated="grdList_RowCreated">
                        <Columns>
    
                        </Columns>
                    </asp:GridView>
                </ContentTemplate>
                <Triggers>
                    <asp:AsyncPostBackTrigger ControlID="btnDelete" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="btnNew" EventName="Click" />
                    <asp:AsyncPostBackTrigger ControlID="btnForward" EventName="Click" />
                </Triggers>
            </asp:UpdatePanel>
    
            <asp:Button ID="btnDelete" runat="server" SkinID="Button" Text="<%$ Resources: CommonResources, btnDelete %>"
                OnClick="btnDelete_Click" />
            <asp:Button ID="btnNew" runat="server" SkinID="Button" Text="<%$ Resources: CommonResources, btnNew %>"
                OnClick="btnNew_Click" />
            <asp:Button ID="btnForward" runat="server" SkinID="Button" meta:resourcekey="btnForward"
                OnClick="btnForward_Click" />
    
    2 回复  |  直到 12 年前
        1
  •  1
  •   Nasser Hadjloo    15 年前

    很明显,你的页面(模块)在页面加载事件中做了一些事情,而这个事件阻止了potbacking你的按钮。

    我的意思是你试着回发,页面加载事件再次运行,所有的东西第一次出现,

    我遇到了这个问题,通过

      if(!IsPostBack)
          DoSomething();
    
        2
  •  0
  •   dimcookies    12 年前
    <asp:UpdatePanel ID="UpdatePanel1" ChildrenAsTriggers="False" UpdateMode="Conditional" runat="server">
                <ContentTemplate> 
       <form id="form1" runat="server"  defaultbutton="btnSearch">
    
       <div>
                 <asp:ScriptManager ID="ScriptManager1" EnablePartialRendering="true"
    runat="server">
            </asp:ScriptManager>
       <script language="javascript" type="text/javascript"> 
    
    
    
       var prm = Sys.WebForms.PageRequestManager.getInstance(); 
    
       prm.add_initializeRequest(InitializeRequest); 
       prm.add_endRequest(EndRequest); 
       var postBackElement; 
       function InitializeRequest(sender, args) 
       { 
    
          if (prm.get_isInAsyncPostBack()) 
             args.set_cancel(true); 
          postBackElement = args.get_postBackElement(); 
          if (postBackElement.id == 'btnSearch') 
             $get('UpdateProgress1').style.display = 'block'; 
    
       } 
    
    
    
       function EndRequest(sender, args) 
       { 
           if (postBackElement.id == 'btnSearch') 
              $get('UpdateProgress1').style.display = 'none'; 
    
       } 
    
    
    
    </script>
        </div>        
    
    
           <asp:GridView ID>
    
            <Columns>
              <asp:TemplateField>
                 <HeaderTemplate>
                 <asp:Label ID="Label2" runat="server" Text="Status"></asp:Label>  
                  <asp:CheckBox ID="chkSelectAll" runat="server"  onclick="javascript:HighlightRow(this);"
                  AutoPostBack="true"  ToolTip="Click here to select all checkboxes"
                  OnCheckedChanged="chkSelectAll_CheckedChanged"/>
                 </HeaderTemplate>
                 <ItemTemplate >
    
                 <asp:CheckBox ID="CheckBox1" onclick="javascript:HighlightRow(this);" 
                            AutoPostBack="true" runat="server"
                            OnCheckedChanged="CheckBox1_CheckedChanged1" />
    
    
                </ItemTemplate>
    
                </asp:TemplateField>
    
        <asp:BoundField
    </asp:GridView>
    
    </ContentTemplate>
           <Triggers> 
                <asp:AsyncPostBackTrigger  ControlID="btnSearch"  EventName="Click"/>
    
            </Triggers>
            </asp:UpdatePanel>
              <asp:UpdateProgress ID="UpdateProgress1"  AssociatedUpdatePanelID="UpdatePanel1"  runat="server" ><ProgressTemplate>
                     <asp:Image ID="Imgwait" runat="server" 
                         ImageUrl="~/Content/images/images/ApImages/001413_0.gif" />
                     <asp:Label ID="Lblwait" runat="server" 
                         Text="Please wait while we process your request...." Font-Names="Tahoma" 
                         Font-Size="10px" ForeColor="#990000"></asp:Label>
    </ProgressTemplate>
    </asp:UpdateProgress>
    
       <div style="position: absolute;left:55%;top: 65%; vertical-align:middle; width:300px; text-align:center">
     <asp:Panel ID="IMGDV" runat="server"  Width="300px"  
                BackColor="#3D3327" Visible="False" BorderStyle="Outset">
             <asp:Image ID="Image4" runat="server" 
                 ImageUrl=" " Width="16px" 
                 ToolTip="write your notes here for closure" />
       <asp:Label ID="Label1" runat="server"  CssClass="GridHeader" 
                 Text="Please Provide note ."></asp:Label>
        <table style="border-style: solid; border-width: thin; width: 100%; background-color: #D3CCC2;"><tr><td style=" text-align:center">
    
    
            <asp:TextBox ID="TextBox2" Textmode="MultiLine"  Height="80px" Width="250px" 
                CssClass="heading1" runat="server" ontextchanged="TextBox2_TextChanged" 
                BackColor="#D9D9CA" BorderColor="#3E1F00" BorderStyle="Inset"></asp:TextBox>
        </td></tr>
        </table>
    
       <table  style="border-style: outset; border-width: medium; width: 100%; background-color: #BDB2A4;">
       <tr>
    
        <td style=" text-align:left">
        <asp:panel runat="server" ID="pnlsub" BackColor="#3D3327" 
             BorderStyle="Outset" Width="90%" ToolTip="Submit">
    
             <asp:Button ID="Button1" runat="server" Text="Submit" CssClass="Button"  BorderStyle="Solid" BorderColor="#3D3327" onclick="Button1_Click"/>
                             </asp:panel>
            </td>
            <td style=" text-align:left">
            <asp:panel runat="server" ID="pnlcan" BackColor="#3D3327" 
             BorderStyle="Outset" Width="90%" ToolTip="Cancel">
    
                 <asp:Button ID="Button2" runat="server" Text="Cancel" CssClass="Button" BorderStyle="Solid" BorderColor="#3D3327" onclick="Button2_Click"/>  
                 </td>
             </tr>
                 </table>
            </asp:Panel >
        </div>
    

    代码落后

    protected void CheckBox1_CheckedChanged1(object sender, EventArgs e)
            {
     IMGDV.Visible = true;
    
    }
    

    选中复选框时,更改事件希望显示面板控件,但不显示面板控件 帮助…