Click here to Skip to main content
15,884,353 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
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

XML
<%@ 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

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.
Posted
Updated 28-Nov-12 4:44am
v2

1 solution

You must run hide not show to close.

C#
protected void btnOk_Click(object sender, EventArgs e)
{
this.ModalPopupExtender1.Hide();
}
 
Share this answer
 
Comments
tssrajkumar@gmail.com 28-Nov-12 10:46am    
that was my mistake, Its not working when i put "this.ModalPopupExtender1.Hide();" like yours.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900