本文介绍了通过单击按钮无法关闭ajax modelpopupextender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用ajax modelmodelpopupextender在asp面板中的gridview中查看某些内容.当我在另一个gridview中单击链接按钮时,以上网格应显示在扩展器中.
它的工作正常,但我无法通过单击扩展器面板中的按钮来关闭该扩展器.


我的代码是
aspx

I Using ajax modelmodelpopupextender to view some content in a gridview which is in a asp panel. when i click a link button in another gridview the above grid should show in the extender.
its working fine but i could not close that extender by clicking a button which is in the extender panel.


my code is
aspx

<%@ Page Language="C#" MasterPageFile="~/pages/OAT.master" AutoEventWireup="true" CodeFile="Alltest.aspx.cs" Inherits="pages_Alltest" Title="Untitled Page" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<script src="../scripts/jquery-1.7.2.js" type="text/javascript"></script>
<script type="text/javascript">
function conditionalHide(clientID)
{
    if (confirm('You sure?'))
    {
        $find(clientID).hide();
    }
}
</script>
<asp:Panel ID="panAllQuestions" runat="server">
<asp:Label ID="lblMessage"  runat=server CssClass="errorlabel"></asp:Label>
<asp:GridView ID="gridAllTest" DataKeyNames="testname"  runat="server" AutoGenerateColumns="False" CellPadding="3" GridLines="Both" BackColor="White" BorderColor="#4A3C8C" BorderStyle="Solid" BorderWidth="1px" OnRowCommand="gridAllTest_RowCommand" >

<Columns>
<asp:TemplateField HeaderText="S.No">
   <ItemTemplate>
       <%# ((GridViewRow)Container).RowIndex + 1%>
   </ItemTemplate>
    <ItemStyle CssClass="reportitemstyle" />
</asp:TemplateField>

<%--<asp:boundfield datafield="testname"  headertext="Test Name" ItemStyle-CssClass="reportitemstyle"/>--%>

<asp:TemplateField HeaderText="Test Name">
<ItemTemplate>
<asp:Label ID="lblgvTestname" runat="server" Text='<%# Eval("testname") %>' ></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Employee Name">
<ItemTemplate>
<asp:Label ID="lblgvEmpName" runat="server" Text='<%# Eval("empname") %>' Width="100px"></asp:Label>
<asp:Label ID="lblgvUsername" runat="server" Text='<%# Eval("username") %>' Visible="false"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Total Questions">
<ItemTemplate>
<asp:Label ID="lblgvtotQues" runat="server" Text='<%# Eval("totQues") %>' Width="100px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Time">
<ItemTemplate>
<asp:Label ID="lblgvtimeInMin" runat="server" Text='<%# Eval("timeInMin") %>' Width="50px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>


<asp:TemplateField HeaderText="IsAttended">
<ItemTemplate>
<%--<asp:Label ID="lblgvattended" runat="server" Text='<%# Eval("attended") %>' Width="50px"></asp:Label>--%>
<asp:LinkButton ID="lkbgvAttend" runat="server" Text='<%# findAttended(Eval("attended")) %>' Width="150px" CommandName="AttendTest"></asp:LinkButton>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="View">
<ItemTemplate>
<%--<asp:Label ID="lblgvattended" runat="server" Text='<%# Eval("attended") %>' Width="50px"></asp:Label>--%>
<asp:LinkButton ID="lkbView" runat="server"   CommandName="detailView" CssClass="ViewDetail" Width="20px"></asp:LinkButton>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

</Columns>
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
    <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
    <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
    <AlternatingRowStyle BackColor="#F7F7F7" />

</asp:GridView>
</asp:Panel>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<cc1:ModalPopupExtender BehaviorID="ModalPopupExtender1" ID="ModalPopupExtender1" runat="server" TargetControlID="pnlpopup" PopupControlID="pnlpopup"

 BackgroundCssClass="modalBackground" CancelControlID="btnOk" OkControlID="btnOk" DropShadow="true" >
</cc1:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="400px" ScrollBars="both"  style="display:none">
<table style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#D55500">
<td colspan="2" style=" color:White; font-weight:bold; font-size:larger" align="center">Question Details</td>
</tr>
<tr>
<td>
<asp:GridView ID="gridTestDetail"  runat="server" AutoGenerateColumns="False" CellPadding="3" GridLines="Both" BackColor="White" BorderColor="#4A3C8C" BorderStyle="Solid" BorderWidth="1px" >

<Columns>
<asp:TemplateField HeaderText="S.No">
   <ItemTemplate>
       <%# ((GridViewRow)Container).RowIndex + 1%>
   </ItemTemplate>
    <ItemStyle CssClass="reportitemstyle" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Emp.Name">
<ItemTemplate>
<asp:Label ID="lblEmpnamedetail" runat="server" Text='<%# Eval("empname") %>' Width="100px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Test">
<ItemTemplate>
<asp:Label ID="lblTestdetail" runat="server" Text='<%# Eval("test") %>' Width="100px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Question Type">
<ItemTemplate>
<asp:Label ID="lblQtypedetail" runat="server" Text='<%# Eval("questiontype") %>' Width="100px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="User Answer">
<ItemTemplate>
<asp:Label ID="lblUanswerdetail" runat="server" Text='<%# Eval("user_ans") %>' Width="100px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

<asp:TemplateField HeaderText="Right Answer">
<ItemTemplate>
<asp:Label ID="lblRanswerdetail" runat="server" Text='<%# Eval("right_ans") %>' Width="100px"></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="reportitemstyle" HorizontalAlign="center" />
</asp:TemplateField>

</Columns>
<RowStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" />
    <FooterStyle BackColor="#B5C7DE" ForeColor="#4A3C8C" />
    <PagerStyle BackColor="#E7E7FF" ForeColor="#4A3C8C" HorizontalAlign="Right" />
    <SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="#F7F7F7" />
    <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#F7F7F7" />
    <AlternatingRowStyle BackColor="#F7F7F7" />

</asp:GridView>
</td>
</tr>
<tr>
<td>
<%--<asp:Button ID="btnCancel" Text="Cancel"  runat="server" CssClass="CSSButton" />--%>
<asp:Button ID="btnOk" runat="server" Text="Okay" CssClass="CSSButton" OnClick="btnOk_Click" />
</td>
</tr>
</table>

</asp:Panel>

</asp:Content>



aspx.cs

使用系统;
使用System.Data;
使用System.Configuration;
使用System.Collections;
使用System.Web;
使用System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;
使用System.Collections.Generic;
using System.DirectoryServices;
using MySql.Data.MySqlClient;

public partial class pages_Alltest : System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{
selectUseralltests();

}
functionalclass fc = new functionalclass();
public void selectUseralltests()
{
DataSet ds = new DataSet();
ds = fc.selectallusertest(SessinHandler.UserName);
如果(ds.Tables [0] .Rows.Count> 0)
{
gridAllTest.DataSource = ds.Tables[0];
gridAllTest.DataBind();
}
其他
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridAllTest.DataSource = ds;
gridAllTest.DataBind();
int columncount = gridAllTest.Rows[0].Cells.Count;
gridAllTest.Rows[0].Cells.Clear();
gridAllTest.Rows[0].Cells.Add(new TableCell());
gridAllTest.Rows[0].Cells[0].ColumnSpan = columncount;
gridAllTest.Rows[0].Cells[0].Text = "No Records Found";
}
}
public string findAttended(object ob)
{
string find = ob.ToString();
if (find != "0")
{
return "Attended";
}
其他
{
return "Click To Attend";
}
}

protected void gridAllTest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AttendTest")
{
LinkButton lb = (LinkButton)e.CommandSource;
GridViewRow selectedRow = (GridViewRow)lb.Parent.Parent;
string testname = selectedRow.Cells[1].Text;
if (lb.Text != "Attended")
{
SessinHandler.test = testname;
Response.Redirect("../pages/Test.aspx");
}
其他
{
lblMessage.Text = testname + " Already Attended";
}

//int Index = Convert.ToInt32(e.CommandArgument);
//GridViewRow gvrow = ((GridView)e.CommandSource).Rows[Index];
//Label testname = gvrow.FindControl("lblgvTestName") as Label;
//SessinHandler.test = testname.Text;
//Response.Redirect("../pages/Test.aspx");
}
else if (e.CommandName == "detailView")
{
GridViewRow gvrow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
//int RowIndex = oItem.RowIndex;
Label testname = gvrow.FindControl("lblgvTestname") as Label;
DataSet ds = new DataSet();
ds = fc.selectuserTestRecord(SessinHandler.UserName, testname.Text);
如果(ds.Tables [0] .Rows.Count> 0)
{
gridTestDetail.DataSource = ds.Tables[0];
gridTestDetail.DataBind();
this.ModalPopupExtender1.Show();

//this.ModalPopupExtender1.Hide();
}
}
}

protected void btnOk_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();//not working
--------------------
}
}

any one Please help me.



aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.DirectoryServices;
using MySql.Data.MySqlClient;

public partial class pages_Alltest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
selectUseralltests();

}
functionalclass fc = new functionalclass();
public void selectUseralltests()
{
DataSet ds = new DataSet();
ds = fc.selectallusertest(SessinHandler.UserName);
if (ds.Tables[0].Rows.Count > 0)
{
gridAllTest.DataSource = ds.Tables[0];
gridAllTest.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridAllTest.DataSource = ds;
gridAllTest.DataBind();
int columncount = gridAllTest.Rows[0].Cells.Count;
gridAllTest.Rows[0].Cells.Clear();
gridAllTest.Rows[0].Cells.Add(new TableCell());
gridAllTest.Rows[0].Cells[0].ColumnSpan = columncount;
gridAllTest.Rows[0].Cells[0].Text = "No Records Found";
}
}
public string findAttended(object ob)
{
string find = ob.ToString();
if (find != "0")
{
return "Attended";
}
else
{
return "Click To Attend";
}
}

protected void gridAllTest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AttendTest")
{
LinkButton lb = (LinkButton)e.CommandSource;
GridViewRow selectedRow = (GridViewRow)lb.Parent.Parent;
string testname = selectedRow.Cells[1].Text;
if (lb.Text != "Attended")
{
SessinHandler.test = testname;
Response.Redirect("../pages/Test.aspx");
}
else
{
lblMessage.Text = testname + " Already Attended";
}

//int Index = Convert.ToInt32(e.CommandArgument);
//GridViewRow gvrow = ((GridView)e.CommandSource).Rows[Index];
//Label testname = gvrow.FindControl("lblgvTestName") as Label;
//SessinHandler.test = testname.Text;
//Response.Redirect("../pages/Test.aspx");
}
else if (e.CommandName == "detailView")
{
GridViewRow gvrow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
//int RowIndex = oItem.RowIndex;
Label testname = gvrow.FindControl("lblgvTestname") as Label;
DataSet ds = new DataSet();
ds = fc.selectuserTestRecord(SessinHandler.UserName, testname.Text);
if (ds.Tables[0].Rows.Count > 0)
{
gridTestDetail.DataSource = ds.Tables[0];
gridTestDetail.DataBind();
this.ModalPopupExtender1.Show();

//this.ModalPopupExtender1.Hide();
}
}
}

protected void btnOk_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();//not working
--------------------
}
}

any one Please help me.

推荐答案



aspx.cs

使用系统;
使用System.Data;
使用System.Configuration;
使用System.Collections;
使用System.Web;
使用System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
使用System.Web.UI.WebControls.WebParts;
使用System.Web.UI.HtmlControls;
使用System.Collections.Generic;
using System.DirectoryServices;
using MySql.Data.MySqlClient;

public partial class pages_Alltest : System.Web.UI.Page
{
受保护的void Page_Load(对象发送者,EventArgs e)
{
selectUseralltests();

}
functionalclass fc = new functionalclass();
public void selectUseralltests()
{
DataSet ds = new DataSet();
ds = fc.selectallusertest(SessinHandler.UserName);
如果(ds.Tables [0] .Rows.Count> 0)
{
gridAllTest.DataSource = ds.Tables[0];
gridAllTest.DataBind();
}
其他
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridAllTest.DataSource = ds;
gridAllTest.DataBind();
int columncount = gridAllTest.Rows[0].Cells.Count;
gridAllTest.Rows[0].Cells.Clear();
gridAllTest.Rows[0].Cells.Add(new TableCell());
gridAllTest.Rows[0].Cells[0].ColumnSpan = columncount;
gridAllTest.Rows[0].Cells[0].Text = "No Records Found";
}
}
public string findAttended(object ob)
{
string find = ob.ToString();
if (find != "0")
{
return "Attended";
}
其他
{
return "Click To Attend";
}
}

protected void gridAllTest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AttendTest")
{
LinkButton lb = (LinkButton)e.CommandSource;
GridViewRow selectedRow = (GridViewRow)lb.Parent.Parent;
string testname = selectedRow.Cells[1].Text;
if (lb.Text != "Attended")
{
SessinHandler.test = testname;
Response.Redirect("../pages/Test.aspx");
}
其他
{
lblMessage.Text = testname + " Already Attended";
}

//int Index = Convert.ToInt32(e.CommandArgument);
//GridViewRow gvrow = ((GridView)e.CommandSource).Rows[Index];
//Label testname = gvrow.FindControl("lblgvTestName") as Label;
//SessinHandler.test = testname.Text;
//Response.Redirect("../pages/Test.aspx");
}
else if (e.CommandName == "detailView")
{
GridViewRow gvrow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
//int RowIndex = oItem.RowIndex;
Label testname = gvrow.FindControl("lblgvTestname") as Label;
DataSet ds = new DataSet();
ds = fc.selectuserTestRecord(SessinHandler.UserName, testname.Text);
如果(ds.Tables [0] .Rows.Count> 0)
{
gridTestDetail.DataSource = ds.Tables[0];
gridTestDetail.DataBind();
this.ModalPopupExtender1.Show();

//this.ModalPopupExtender1.Hide();
}
}
}

protected void btnOk_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();//not working
--------------------
}
}

any one Please help me.



aspx.cs

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;
using System.DirectoryServices;
using MySql.Data.MySqlClient;

public partial class pages_Alltest : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
selectUseralltests();

}
functionalclass fc = new functionalclass();
public void selectUseralltests()
{
DataSet ds = new DataSet();
ds = fc.selectallusertest(SessinHandler.UserName);
if (ds.Tables[0].Rows.Count > 0)
{
gridAllTest.DataSource = ds.Tables[0];
gridAllTest.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
gridAllTest.DataSource = ds;
gridAllTest.DataBind();
int columncount = gridAllTest.Rows[0].Cells.Count;
gridAllTest.Rows[0].Cells.Clear();
gridAllTest.Rows[0].Cells.Add(new TableCell());
gridAllTest.Rows[0].Cells[0].ColumnSpan = columncount;
gridAllTest.Rows[0].Cells[0].Text = "No Records Found";
}
}
public string findAttended(object ob)
{
string find = ob.ToString();
if (find != "0")
{
return "Attended";
}
else
{
return "Click To Attend";
}
}

protected void gridAllTest_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "AttendTest")
{
LinkButton lb = (LinkButton)e.CommandSource;
GridViewRow selectedRow = (GridViewRow)lb.Parent.Parent;
string testname = selectedRow.Cells[1].Text;
if (lb.Text != "Attended")
{
SessinHandler.test = testname;
Response.Redirect("../pages/Test.aspx");
}
else
{
lblMessage.Text = testname + " Already Attended";
}

//int Index = Convert.ToInt32(e.CommandArgument);
//GridViewRow gvrow = ((GridView)e.CommandSource).Rows[Index];
//Label testname = gvrow.FindControl("lblgvTestName") as Label;
//SessinHandler.test = testname.Text;
//Response.Redirect("../pages/Test.aspx");
}
else if (e.CommandName == "detailView")
{
GridViewRow gvrow = (GridViewRow)((LinkButton)e.CommandSource).NamingContainer;
//int RowIndex = oItem.RowIndex;
Label testname = gvrow.FindControl("lblgvTestname") as Label;
DataSet ds = new DataSet();
ds = fc.selectuserTestRecord(SessinHandler.UserName, testname.Text);
if (ds.Tables[0].Rows.Count > 0)
{
gridTestDetail.DataSource = ds.Tables[0];
gridTestDetail.DataBind();
this.ModalPopupExtender1.Show();

//this.ModalPopupExtender1.Hide();
}
}
}

protected void btnOk_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();//not working
--------------------
}
}

any one Please help me.


protected void btnOk_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();
}


这篇关于通过单击按钮无法关闭ajax modelpopupextender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 09:26