ajax modalpopupextender不是从代码后面触发的

时间:2013-06-30 16:12:37

标签: c# asp.net ajax ajaxcontroltoolkit modalpopupextender

我想在单击按钮后执行代码中的模式弹出窗口,执行操作,接下来就是显示模态弹出窗口。我有modalpopupextender,popup,按钮设置为display:none,因此模态弹出窗口不会抛出错误。

我在gridview中有一个imagebutton,我在后面的代码中触发动作,一旦执行了动作,我希望显示模态弹出窗口。

这就是我所拥有的。标记:

<%@ Page Language="C#" MasterPageFile="~/EmployerMasterPage.master" AutoEventWireup="true"
    CodeFile="JobPostingList.aspx.cs" Inherits="Employer_JobPostingList" ValidateRequest="false" %>

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="emplhelp">
        <table cellspacing="0" cellpadding="0" class="cdiv1 border_none">           
            <tr>
                <td valign="top">
                    <table cellpadding="0" cellspacing="0" class="grayborder subtblE">
                        <tr>
                            <td class="pad_grid">
                                <asp:GridView ID="GridView1" class="grdtxt gridvw" runat="server" AutoGenerateColumns="False"
                                    AllowPaging="True" PageSize="20" DataKeyNames="PostingID" BackColor="White" BorderColor="Gray"
                                    BorderStyle="Solid"
                                    Width="100%" BorderWidth="1" CellPadding="3" GridLines="Vertical" EmptyDataText="No Results."
                                    OnDataBound="GridView1_DataBound" OnPageIndexChanging="GridView1_PageIndexChanging">
                                    <Columns>                                                            
                                        <asp:BoundField DataField="Location" HeaderText="Location" />
                                        <asp:BoundField DataField="PostingStatus2" HeaderText="Posting Status" ItemStyle-HorizontalAlign="center" />
                                        <asp:BoundField DataField="DatePosted" HeaderText="Date Posted" DataFormatString="{0:dd/MMM/yyy}"
                                            HtmlEncode="false" ItemStyle-HorizontalAlign="Center" />                                                                                           

                                        <asp:TemplateField HeaderText="Edit" ItemStyle-HorizontalAlign="Center">
                                           <ItemTemplate>                                               
                                               <asp:ImageButton ID="imgButton1" RowIndex='<%# Eval("PostingID") %>' OnClick="imgButton1_Click" runat="server" ImageUrl="/images/a.png" />
                                           </ItemTemplate>
                                                </asp:TemplateField>
                                    </Columns>                           
                                </asp:GridView>

                            </td>
                        </tr>
                        <tr>
                            <td>
                                &nbsp;
                            </td>
                        </tr>                     
                    </table>
                </td>
            </tr>
        </table>
               <asp:Button ID="btnShowPopup" runat="server" style="display:none" />
    </div>
  <!-- LOGIN PANEL -->    
       <asp:Panel ID="pnlConfirm" runat="server" CssClass="modalPanel" Style="display: none; height:160px;">

        <div>
                      <table class="featrEmpDivLoginPopup" style="height:160px; width:460px;" cellspacing="0" cellpadding="0">
                <tr>
                    <td id="divClose" runat="server" class="topimglhs533 hedding1" style="height:30px; background-color:#d3d8d2;">
                        Message 
                    </td>
                </tr>
                <tr>
                    <td>
                        <div id="jsAlert1_popupBody" style="position: absolute; font-family: Verdana,Arial; font-size: 9pt; padding: 2px; text-align: left; background-color: rgb(255, 255, 255); color: black; top: 34px; width: 450px; left: 1px;">
<div style="padding-left:25px; padding-right:25px; padding-top:5px; padding-bottom:5px;">Are you sure you want to Archive this posting?<br></div>
</div>
                    </td>
                </tr>
                          <tr>
    <td style="width:100px; margin-top:5px; padding-left:50px;">
        <asp:ImageButton ID="btnUpdate" ImageUrl="~/Images/btnarchive.jpg" OnClick="btnUpdate_Click" runat="server" />
        <asp:ImageButton ID="btnCancel" ImageUrl="~/Images/cancel.jpg" runat="server" />
        <asp:HiddenField ID="hfPostingID" runat="server" />
</td>
</tr>

            </table>
        </div>
    </asp:Panel>
<ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlConfirm"
CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</ajaxToolkit:ModalPopupExtender>       
    <!-- LOGIN PANEL -->
</asp:Content>

然后在后面的代码中我有这个:

protected void imgButton1_Click(object sender, ImageClickEventArgs e)
    {
        ImageButton btndetails = sender as ImageButton;
        GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
        string postingID = btndetails.Attributes["RowIndex"];
        if (postingID != string.Empty)
        {
            hfPostingID.Value = postingID;
        }
        ModalPopupExtender1.Show();

      //  this.ModalPopupExtender1.Show();

    }

正如你所看到的,我尝试了这两个.ModalPopupExtender1和ModalPopupExtender,但我得到了同样的回复。

1 个答案:

答案 0 :(得分:0)

在我面前没有Visual Studio;但以下将有助于您朝着正确的方向前进!

将ImageButton标记替换为如下:

<asp:ImageButton ID="imgButton1" commandName="Click" commandArgument='<%# Eval("PostingID") %>' runat="server" ImageUrl="/images/a.png" />

并在后面的代码中,而不是使用gridview的RowCommand事件代替图像按钮的click事件:

    private sub GridView1_RowCommand(.......) handles ....

    dim xvar=e.commandArgument
    if e.commandName="Click" then
    ...use the **xvar**  to perform custom task before you show the modal popup...
    find the modalPopupControlExtender using FindControl and then use the .SHOW() property
    ...
    ...
    end if

end sub