ajax modalpopupextender未从代码后面触发
本文关键字:代码 modalpopupextender ajax | 更新日期: 2023-09-27 18:20:24
我想在代码后面显示一个模式弹出窗口,一旦点击按钮,执行操作,接下来就是显示模式弹出窗口。我有modalpopupextender,popup,按钮,它被设置为display:none
,所以模式弹出不会抛出错误。
我在网格视图中有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>
</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和ModalPopup Extender,但我得到了相同的响应。
不要让Visual Studio出现在我面前;但以下内容将帮助你朝着正确的方向前进,希望如此!
替换ImageButton标签如下:
<asp:ImageButton ID="imgButton1" commandName="Click" commandArgument='<%# Eval("PostingID") %>' runat="server" ImageUrl="/images/a.png" />
在后面的代码中,使用gridview的RowCommand事件代替图像按钮的点击事件:
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