我无法通过代码使ModalPopupExtender工作。如果我设置ModalPopupExtender的属性TargetControlID =“btn”,它可以工作。当我将TargetControlID =“HiddenField1”设置为在代码中使用mpe.show()方法时,它不起作用(dgvResults_RowCommand事件触发正常,我已经测试过它)。我经历了许多查看代码的网站,并且无法弄清楚什么是错误的。在此先感谢您的任何帮助
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
CodeBehind="Default.aspx.cs" Inherits="Michlala._Default" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
<style type="text/css">
.modalPopup
{
background-color: Black;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}
.style1
{
width: 100%;
}
.style5
{
text-align: center;
}
</style>
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h1> Student Feedback</h1>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<br />
<asp:TextBox ID="txtSID" runat="server" Width="61px" Height="25px"></asp:TextBox>
<asp:Button ID="btnSID" runat="server" onclick="Button1_Click"
Text="Submit Student ID" />
<asp:GridView ID="dgvResults" runat="server" Visible="False"
onrowcommand="dgvResults_RowCommand">
<Columns>
<asp:TemplateField>
<EditItemTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Button ID="btnFeedback" runat="server" onclick="Button1_Click1"
Text="Add FeedBack" CommandName="InsertFeedback" CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
<asp:HiddenField ID="HiddenField1" runat="server" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
TargetControlID="HiddenField1"
PopupControlID="pnlModalPanel"
CancelControlID="btnCancel"
BackgroundCssClass="modalPopup" >
</asp:ModalPopupExtender>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Panel ID="pnlModalPanel" runat="server" style="display:none" Width="481px" >
<table class="style1">
<tr>
<td>
Course
</td>
<td>
Semester
</td>
<td class="style5">
Teacher Assitant
</td>
<td class="style5">
Lecturer
</td>
</tr>
<tr>
<td>
 
<asp:TextBox ID="txtCourse" runat="server"></asp:TextBox>
</td>
<td>
 
</td>
<td>
 
</td>
<td>
 
</td>
</tr>
<tr>
<td colspan="2" style="text-align: center">
<asp:Button ID="btnSubmit" runat="server" Text="Submit" />
</td>
<td colspan="2">
 
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
<asp:DropDownList ID="ddlSemester" runat="server">
</asp:DropDownList>
<asp:Label ID="lblRes" runat="server" Text="Label"></asp:Label>
<br />
</asp:Content>
在服务器端代码
protected void dgvResults_RowCommand(object sender, GridViewCommandEventArgs e)
{
ModalPopupExtender mpe = new ModalPopupExtender();
mpe.Show();
}
答案 0 :(得分:1)
您需要在所选行中找到ModalPopupExtender,然后使用名称调用它:
if (e.CommandName.Equals("InsertFeedback"))
{
int index = Convert.ToInt32(e.CommandArgument);
// Retrieve the row that contains the button clicked
// by the user from the Rows collection.
GridViewRow row = dgvResults.Rows[index];
ModalPopupExtender mpe = (ModalPopupExtender)row.FindControl("ModalPopupExtender1");
mpe.Show();
}