Cannot get the ModalPopupExtender to run via code
I cannnot get the ModalPopupExtender to work via code. If I set the ModalPopupExtender's property TargetControlID="btn", it works. When I set TargetControlID="HiddenField1" to use the mpe.show() method in the code, it does not work (the dgvResults_RowCommand event fires fine, I have tested it). I have gone through many sites looking at code, and cannot figure out whats wrong. Thanks in advance for any help
<%@ 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"
CancelControlI开发者_StackOverflow社区D="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>
in the server side code
protected void dgvResults_RowCommand(object sender, GridViewCommandEventArgs e)
{
ModalPopupExtender mpe = new ModalPopupExtender();
mpe.Show();
}
You need to fin the ModalPopupExtender in the selected row and then call it with the name:
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();
}
精彩评论