AjaxModalPopupExtender在第一次单击后显示弹出窗口,然后在后续调用时显示,而不触发按钮单击事件

时间:2011-11-30 06:58:05

标签: asp.net ajax

当用户点击gridview中的Place按钮时,我必须显示一个弹出窗口,请记住,当用户点击 Place 按钮时,我必须在模块级变量中捕获commandArgument的值这样我就可以在数据库中更新它。 现在,当页面显示并且用户单击放置按钮时,页面回发到服务器然后弹出,同时我捕获代码后面的按钮的commandargument值。但是,在第一次单击按钮后,单击按钮会显示弹出窗口而不在服务器上发送页面。也就是说,它没有触发 Place 按钮的onClick事件,模块级变量中的值保持不变。之后,如果用户从弹出窗口中选择“确定”按钮,则会在首先调用放置按钮时更新在模块级别变量中设置的值。

我该怎么办? 我的代码中有错误吗?

<GridView id= "Grd" runat="server" AutoGenerateColumns="false" CssClass="GridStyle" 
           HeaderStyle-Font-Size="Small" Width="960" Visible="false">
          <Columns>          

          'Columns goes here          
          <asp:TemplateField HeaderText="Action" HeaderStyle-Width="310px" ItemStyle-HorizontalAlign="Left">
          <ItemTemplate>
              <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" 
              CommandArgument='<%#Eval("intHireEnquiryID") %>' />
              <asp:Button ID="btnPlace" runat="server" Text="Place" OnClick="btnPlace_Click"  
              CommandArgument='<%#Eval("intHireEnquiryID") %>' />
              <ajaxtk:ModalPopupExtender runat="server" ID="actPopup" TargetControlID="btnPlace" 
              PopupControlID="pnlPopup" CancelControlID="btnCancel" >
              </ajaxtk:ModalPopupExtender>
          </ItemTemplate>
          </asp:TemplateField>
          </Columns>          
          </GridView>          

InPanel我有两个按钮PlaceFinal和Cancel,用于最终放置和取消请求。

在Code Behind中,我称之为: -

Dim popup As New AjaxControlToolkit.ModalPopupExtender
        Dim i As Integer
        For i = 0 To Grd.Rows.Count - 1
            popup = Grd.Rows(i).FindControl("actPopup")
            popup.Show()
        Next
        pnlPopup.Visible = True

是否有任何属性或我遗漏的任何其他内容,以便“点击”按钮点击事件不会从第二次点击开始。那为什么它第一次点击工作?

按钮的onclick事件仅在第一次工作,而不是在此之后。

1 个答案:

答案 0 :(得分:0)

<GridView id= "Grd" runat="server" AutoGenerateColumns="false" CssClass="GridStyle"  
           HeaderStyle-Font-Size="Small" Width="960" Visible="false"> 
          <Columns>           

          'Columns goes here           
          <asp:TemplateField HeaderText="Action" HeaderStyle-Width="310px" ItemStyle-HorizontalAlign="Left"> 
          <ItemTemplate> 
              <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click"  
              CommandArgument='<%#Eval("intHireEnquiryID") %>' /> 
              <asp:Button ID="btnPlace" runat="server" Text="Place" OnClick="btnPlace_Click"   
              CommandArgument='<%#Eval("intHireEnquiryID") %>' /> 

          </ItemTemplate> 
          </asp:TemplateField> 
          </Columns>           
          </GridView>         

删除在gridview中获取的modalpopupextender,并将其保存在如下所示的更新面板中,并记住将modalpopupextender的TargetControlId从实际按钮移除到虚拟按钮,该按钮在页面上没有用处并隐藏它。这个btnDummy只是为了在没有为modalpopup定义targetcontrolid时删除引发错误的错误。

<asp:UpdatePanel ID="upPopupPnl" runat="server" UpdateMode="Conditional">
            <ContentTemplate>            
            <asp:Panel runat="server" ID="pnlPopup" Width="300px" Height="300px" BackColor="Azure" 
            style="overflow:auto;border-color:Black;border-style:solid;border-width:2px;">
            <table><tr><td colspan="2" style="width:300px;">
            <asp:RadioButtonList ID="rbl1" runat="server">
            </asp:RadioButtonList>          
            </td></tr>
            <tr><td style="text-align:center;">
            <asp:Button ID="btnPlacePopup" runat="server" Text="Place" Width="100" Height="35" Font-Bold="true" 
            OnClick="btnPlacePopup_Click" />
            </td>
            <td style="text-align:center;">
            <asp:Button ID="btnCancel" runat="server" Text="Cancel" Width="100" Height="35" Font-Bold="true" />
            </td></tr>
            </table>
            </asp:Panel>
            <asp:Button ID="btnDummy" runat="server" Text="Not Display" style="display:none;"/>
            <ajaxtk:ModalPopupExtender ID="actPopup1" runat="server" TargetControlID="btnDummy" BackgroundCssClass="modalBackground"  
            PopupControlID="pnlPopup" CancelControlID="btnCancel">
            </ajaxtk:ModalPopupExtender> 
            </ContentTemplate>
            </asp:UpdatePanel>

Css类如下: -

.modalBackground 
{ 
  background-color:#B3B3CC; 
  opacity:0.5;
}

代码背后: -

dim intHireEnquiryIDas integer 
Protected Sub btnPlace_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        intHireEnquiryID = CType(sender, Button).CommandArgument
        Dim EXP As New Exception
        Dim params(0) As SqlParameter
        params(0) = New SqlParameter("@intHireEnquiryID", intHireEnquiryID)
        Dim DS As New DataSet
        DS = execQuery("spAgent_Get_Assigned_Workers", executionType.SPExecuteForDS, EXP, params)
        If DS.Tables(0).Rows.Count > 0 Then
            rbl1.DataSource = DS
            rbl1.DataTextField = "WorkerDetail"
            rbl1.DataValueField = "intWorkerID"
            rbl1.DataBind()            
        End If
        upPopupPnl.Update()
        actPopup1.Show()
    End Sub

因此它的工作非常好。 要记住的要点: - 但请记住将modalpopupextender的TargetControlId从实际按钮移除到虚拟按钮,该按钮在页面上没有用处并隐藏它。并且不要设置必须显示为true或false的面板的可见属性。它将由ajaxmodalpopupextender自动处理。 实际上为什么我把一个虚拟按钮作为modalpopup的targetcontrolid因为我需要部分回发页面来更新生成的radiobuttons列表。但是如果我们将主按钮作为targetcontrolid,那么按钮的默认行为将被modalpopup扩展器覆盖,并且它不会回发页面。所以,我拿了一个假按钮。在实际的按钮点击事件中,我生成列表并将其绑定到radiobuttonlist,然后调用更新面板的更新方法,然后调用modalpopup的show方法。 现在好了.... 谢谢!