modalpopup extender in asp.net ajax - asp.net

I have two radio buttons with the same groupname. On selection of the one radio button i want two new radio buttons,and on selection of other radio button i want two other new radio button to be visible.
I want all of these inside the ModalPopupExtender.

Here's an example:
ASPX:
<head runat="server">
<title>Modal Popup</title>
<style type="text/css">
.modalStyle
{
background-color: Gray;
filter: alpha(opacity=70);
opacity: 0.7;
}
.panelStyle
{
width: 300px;
height: 180px;
border: 2px solid Gray;
background-color:White;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="scripManager" runat="server" />
<asp:ModalPopupExtender ID="modal" CancelControlID="btnCancel" BackgroundCssClass="modalStyle" PopupControlID="popup" TargetControlID="lblPopup" runat="server" />
<asp:Label ID="lblPopup" runat="server" />
<asp:Panel runat="server" ID="popup" CssClass="panelStyle">
<table style="width: 100%;">
<tr>
<td>
<asp:RadioButton ID="rdboption1" AutoPostBack="true" OnCheckedChanged="CheckedChanged" runat="server" Text="Option 1" GroupName="Options" /><br />
<asp:RadioButton ID="rdboption11" runat="server" Text="Option 1.1" GroupName="SubOption1"
Visible="false" /><br />
<asp:RadioButton ID="rdboption12" runat="server" Text="Option 1.2" GroupName="SubOption1"
Visible="false" />
</td>
</tr>
<tr>
<td>
<asp:RadioButton ID="rdboption2" AutoPostBack="true" OnCheckedChanged="CheckedChanged" runat="server" Text="Option 2" GroupName="Options" /><br />
<asp:RadioButton ID="rdboption21" runat="server" Text="Option 2.1" GroupName="SubOption2"
Visible="false" /><br />
<asp:RadioButton ID="rdboption22" runat="server" Text="Option 2.2" GroupName="SubOption2"
Visible="false" />
</td>
</tr>
<tr>
<td style="text-align: center;">
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</form>
</body>
Code behind:
public partial class Test : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
modal.Show();
}
protected void CheckedChanged(object sender, EventArgs e)
{
var radioButton = sender as RadioButton;
ResetOptions();
switch(radioButton.ID)
{
case "rdboption1":
rdboption11.Visible = true;
rdboption12.Visible = true;
break;
case "rdboption2":
rdboption21.Visible = true;
rdboption22.Visible = true;
break;
}
}
private void ResetOptions()
{
rdboption11.Visible = false;
rdboption12.Visible = false;
rdboption21.Visible = false;
rdboption22.Visible = false;
}
}

Related

How to maintain DataList item index across Postbacks?

I'm trying to retain the index of the Datalist item on page reload. I'm trying to do this by storing the index into a Session and then setting the index of DataList object equals to the Session. Here's the HTML code:
<asp:DataList ID="MyList" Width="100%" RepeatDirection="Vertical" runat="server"
OnItemDataBound="MyList_ItemDataBound" OnItemCommand="MyList_ItemCommand">
<ItemTemplate>
<table class="table">
<tr>
<td style="width: 5%;">
<asp:Label ID="lbl_id" runat="server" Text='<%# Eval("id") %>' Visible="false" />
<asp:Label ID="lbl_isread" runat="server" Text='<%# Eval("isread") %>' Visible="false" />
<input type="checkbox" id="chk_vd" runat="server" class="chkitem" />
</td>
<td style="width: 15%;">
<asp:HyperLink ID="usr" runat="server" Text='<%# Eval("from") %>' />
</td>
<td style="width: 62%;">
<asp:LinkButton ID="sub" Text='<%# Eval("subject") %>' CommandName="select" runat="server"></asp:LinkButton>
</td>
<td style="width: 18%;">
<asp:Label ID="dt" runat="server" Text='<%# Eval("Date_Added") %>' />
</td>
</tr>
</table>
</ItemTemplate>
<SelectedItemTemplate>
<table class="table">
<tr>
<td style="width: 5%;">
<asp:Label ID="lbl_id" runat="server" Text='<%# Eval("id") %>' Visible="false" />
<asp:Label ID="lbl_isread" runat="server" Text='<%# Eval("isread") %>' Visible="false" />
<asp:Label ID="lbl_messagetype" runat="server" Text='<%# Eval("messagetype") %>'
Visible="false" />
<asp:Label ID="lbl_groupid" runat="server" Text='<%# Eval("groupid") %>' Visible="false" />
<asp:Label ID="lbl_content_id" runat="server" Text='<%# Eval("content_id") %>' Visible="false" />
<asp:Label ID="lbl_sendertype" runat="server" Text='<%# Eval("sendertype") %>' Visible="false" />
<input type="checkbox" id="chk_vd" runat="server" class="chkitem" />
</td>
<td style="padding: 5px; text-align: left; vertical-align: top; width: 15%;">
<uc1:avator ID="avt" runat="server" UserName='<%# Eval("from") %>' PhotoName="" Width="65"
Height="65" />
<br />
<asp:HyperLink ID="usr" runat="server" Text='<%# Eval("from") %>' />
</td>
<td style="padding: 5px; text-align: left; vertical-align: top; width: 62%;">
<div class="item_pad_4">
<h3 id="s_sub" runat="server">
<%# Eval("subject") %>
</h3>
</div>
<asp:Label ID="msg" runat="server" Text='<%# Eval("body") %>'></asp:Label>
<div class="bx_br_tp item_pad_4">
<div class="btn-group" id="<%# Eval("id") %>">
<asp:LinkButton ID="a" CssClass="btn btn-primary btn-xs" runat="server" />
<asp:LinkButton ID="r" CssClass="btn btn-primary btn-xs" runat="server" />
<%-- <asp:LinkButton ID="lnk_spam" CssClass="btn btn-primary btn-xs" runat="server"
Text="spam" CommandName="spam"></asp:LinkButton>--%>
</div>
</div>
</td>
<td style="padding: 5px; text-align: left; vertical-align: top; width: 18%;">
<asp:Label ID="dt" runat="server" Text='<%# Eval("Date_Added") %>' />
</td>
</tr>
</table>
</SelectedItemTemplate>
</asp:DataList>
On the server side, I'm trying to restore the index of the DataList item as follows:
if (!Page.IsPostBack)
{
if (Session["datalist"] != null)
{
((DataList)Session["datalist"]).SelectedIndex = (int)Session["index"];
}
Here's the function which does data binding :
protected void MyList_ItemCommand(object source, DataListCommandEventArgs e)
{
Session["datalist"] = source;
string cmd = ((LinkButton)e.CommandSource).CommandName;
long messageid = long.Parse(((Label)e.Item.FindControl("lbl_id")).Text);
string username = ((HyperLink)e.Item.FindControl("usr")).Text;
// approve / ignore action related values
long content_id = 0;
long groupid = 0;
int messagetype = 0;
int index = e.Item.ItemIndex;
Session["index"] = index;
index = (int)Session["index"];
switch (cmd)
{
case "select":
((DataList)source).SelectedIndex = e.Item.ItemIndex;
int isread = int.Parse(((Label)e.Item.FindControl("lbl_isread")).Text);
// mark message as read it its unread message
if (isread == 0)
{
isread = 1; // message is read
MailBoxBLL.Update_isRead(messageid, isread, Page.User.Identity.Name);
}
string _cache = "usr_msg_cnt_" + UserName;
if (HttpContext.Current.Cache[_cache] != null)
{
Cache.Remove(_cache);
}
break;
This doesn't work and Datalist item does not get selected when the page reloads. How can I make it work?
Any help is appreciated.
Add this directly in Page Load:-
protected void Page_Load(object sender, EventArgs e)
{
if (Session["datalist"] != null)
((DataList)Session["datalist"]).SelectedIndex = (int)Session["index"];
}
The probelm with your code is that the Page.IsPostBack property will be false in the initial get request and for every page reload (actual postback) it will be true. Thus !Page.IsPostBack will become actually false and your code will never execute.

asp.net gridview - spread bound data across multi lines per row with updatepanel

I have a panel inside a gridview and I need it to be 'spread' for the width of the row :
never mind what's in the panel. What I show here is just to demo my needs...My HTML:
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
CellPadding="3"
CssClass="myGrid"
DataKeyNames="Role_Name">
<AlternatingRowStyle BackColor="#E6E6E6" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="imgShow" runat="server" OnClick="Show_Hide_details" BorderStyle="None" BackColor="Transparent" ImageUrl="~/Content/Images/Arrow_Down.png"
CommandArgument="Show" />
<asp:Panel ID="pnlRole" runat="server" Style="position: relative;" Visible="false">
<asp:Label ID="lblAAA" runat="server" Text="aaa" /><br />
<asp:Label ID="lblBBB" runat="server" Text="bbb" /><br />
<asp:Label ID="lblCCC" runat="server" Text="ccc" /><br />
<asp:Label ID="lblDDD" runat="server" Text="ddd" /><br />
</asp:Panel>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Role_Name" HeaderText="Name">
<HeaderStyle Width="100px" />
<ItemStyle CssClass="myGridItemMaxWidth" HorizontalAlign="Left" Wrap="false" />
</asp:BoundField>
<asp:BoundField DataField="Role_Description" HeaderText="Description">
<HeaderStyle Width="150px" />
<ItemStyle CssClass="myGridItemMaxWidth" HorizontalAlign="Left" Wrap="false" />
</asp:BoundField>
</Columns>
<HeaderStyle CssClass="myGridHeader" />
<RowStyle ForeColor="#000066" />
</asp:GridView>
I'd appreciate any help/idea/solution.
EDIT :
To better explain my problem, here's another image :
(never mind what's in the panel. What I show here is just to demo my needs...)
It's tough to do that properly inside of a GridView without it becoming unwieldy.
You would better off with a ListView and using the functionality there.
<asp:ListView ID="ListView1" runat="server"
DataKeyNames="Role_Name"
OnItemCommand="ListView1_ItemCommand">
<LayoutTemplate>
<table class="myGrid">
<thead>
<tr>
<th></th>
<th>Name</th>
<th>Description</th>
</tr>
</theah>
<tbody>
<asp:PlaceHolder ID="itemPlaceholder" runat="server" />
</tbody>
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td>
<asp:ImageButton ID="imgShow" runat="server" BorderStyle="None" BackColor="Transparent" ImageUrl="~/Content/Images/Arrow_Down.png" CommandName="Toggle" />
</td>
<td><%# Eval("Role_Name") %></td>
<td><%# Eval("Role_Description") %></td>
</tr>
<tr>
<td colspan="3">
<asp:Panel ID="pnlRole" runat="server" Style="position: relative;" Visible="false">
<asp:Label ID="lblAAA" runat="server" Text="aaa" /><br />
<asp:Label ID="lblBBB" runat="server" Text="bbb" /><br />
<asp:Label ID="lblCCC" runat="server" Text="ccc" /><br />
<asp:Label ID="lblDDD" runat="server" Text="ddd" /><br />
</asp:Panel>
</td>
</tr>
</ItemTemplate>
<EmptyDataTemplate>
<p>No data found.</p>
</EmptyDataTemplate>
</asp:ListView>
This will unfortunately have an extra <tr>...</tr> for each row. To resolve that, a way you could do this is to use runat="server" for the <tr> in place of the Panel.
<tr id="pnlRole" runat="server" Visible="false">
<td colspan="3">
<asp:Label ID="lblAAA" runat="server" Text="aaa" /><br />
<asp:Label ID="lblBBB" runat="server" Text="bbb" /><br />
<asp:Label ID="lblCCC" runat="server" Text="ccc" /><br />
<asp:Label ID="lblDDD" runat="server" Text="ddd" /><br />
</td>
</tr>
Now in the code-behind you can reference this
protected void ListView1_ItemCommand(object sender, ListViewCommandEventArgs e)
{
if (e.CommandName == "Toggle")
{
HtmlTableRow pnlRole = e.Item.FindControl("pnlRole") as HtmlTableRow;
pnlRole.Visible = !pnlRole.Visible;
ImageButton imgShow = e.Item.FindControl("imgShow") as ImageButton;
if (pnlRole.Visible == true)
imgShow.ImageUrl="~/Content/Images/Arrow_Down.png";
else
imgShow.ImageUrl="~/Content/Images/Arrow_Up.png";
}
}
Here is what I came up with -
On the left is the GridView when all rows are 'closed'. On the right, after 'opening' 2 rows:
Markup:
<form id="form1" runat="server" style="">
<asp:ScriptManager runat="server"></asp:ScriptManager>
<table runat="server" style="font-weight: bold; margin: 0 auto; font-family: Arial;">
<tr>
<td style="text-align: center; width: 500px; overflow: hidden">
<asp:GridView ID="grv_Four_Rows" runat="server"
AutoGenerateColumns="False" BackColor="black" GridLines="None"
CellPadding="3" CssClass="myGrid" DataKeyNames="Test1_First_Name">
<HeaderStyle CssClass="myGridHeader" />
<RowStyle BackColor="#b5c7de" />
<AlternatingRowStyle BackColor="#d1e0e0" />
<Columns>
<asp:TemplateField>
<ItemStyle HorizontalAlign="Left" />
<HeaderTemplate>
<table>
<tr>
<td style="width: 150px;">First</td>
<td style="width: 150px;">Last</td>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<table>
<td>
<asp:UpdatePanel ID="upp_Main_Row" runat="server">
<ContentTemplate>
<asp:Panel runat="server">
<td>
<asp:ImageButton ID="imgShow" runat="server" OnClick="Show_Hide_details"
ImageUrl="~/Content/Images/Arrow_Down.png" CommandArgument="Show" />
</td>
<td style="width: 150px"><%# Eval("Test1_First_Name")%></td>
<td style="width: 150px"><%# Eval("Test1_Last_Name")%></td>
</asp:Panel>
</ContentTemplate>
</asp:UpdatePanel>
</td>
</table>
<table style="border-style: solid; border-width: thin; width: 100%">
<asp:UpdatePanel ID="upp_2nd_row" runat="server" Visible="false">
<ContentTemplate>
<tr>
<td>
<a style="color: red">Address: </a><%# Eval("Test1_Address")%>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upp_3rd_row" runat="server" Visible="false">
<ContentTemplate>
<tr>
<td>
<a style="color: red;">Description: </a><%#Eval("Test1_Description")%>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdatePanel ID="upp_4th_row" runat="server" Visible="false">
<ContentTemplate>
<tr style="float: left">
<td>
<a style="color: red">Note1: </a><%#Eval("Test1_Note_1")%>
<a style="color: red">Note2: </a><%#Eval("Test1_Note_2")%>
</td>
</tr>
</ContentTemplate>
</asp:UpdatePanel>
</table>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</form>
<style type="text/css">
.myGrid {
border: 1px solid black;
-webkit-border-radius: 8px;
-moz-border-radius: 8px;
border-radius: 8px;
overflow: hidden;
background-color: white;
text-align: center;
margin: 0 auto;
}
.myGridHeader > th {
text-align: center;
border: solid 1px;
font-family: Arial;
background-color: #DDFFD6;
font-weight: bold;
color: #000066;
}
</style>
C# code-behind:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
load_grv_Four_Rows();
}
}
//================================================================================================
protected void Show_Hide_details(object sender, EventArgs e)
{
ImageButton imgShowHide = sender as ImageButton;
GridViewRow row = imgShowHide.NamingContainer as GridViewRow;
if (imgShowHide.CommandArgument == "Show")
{
row.FindControl("upp_2nd_Row").Visible = true;
row.FindControl("upp_3rd_Row").Visible = true;
row.FindControl("upp_4th_Row").Visible = true;
imgShowHide.CommandArgument = "Hide";
imgShowHide.ImageUrl = "~/Content/Images/Arrow_Up.png";
}
else
{
row.FindControl("upp_2nd_Row").Visible = false;
row.FindControl("upp_3rd_Row").Visible = false;
row.FindControl("upp_4th_Row").Visible = false;
imgShowHide.CommandArgument = "Show";
imgShowHide.ImageUrl = "~/Content/Images/Arrow_Down.png";
}
}
//================================================================================================
private void load_grv_Four_Rows()
{
try
{
SqlConnection con;
DataSet ds;
con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BETSEFER_DB"].ConnectionString);
string CmdString = "SELECT * FROM tbl_Test1 ORDER BY Test1_First_Name";
ds = new DataSet();
using (SqlDataAdapter sda = new SqlDataAdapter(CmdString, con))
{
sda.Fill(ds);
if (ds.Tables.Count > 0)
{
DataView dv = ds.Tables[0].DefaultView;
grv_Four_Rows.DataSource = dv;
grv_Four_Rows.DataBind();
}
}
}
catch (SqlException ex)
{
Session["mySQL_Error_Msg"] = ex.Message;
Server.ClearError();
Response.Redirect("~/Errors.aspx");
}
}
//================================================================================================
The table:
I still have lots of formatting and cosmetic issues but for those I'll open a new post.
Hope it helps someone.

Can a TargetControlID of a PopUp use the Button of a GridView?

I have a Button with id=btnSend that named "Send" in GridView.
I have a ModalPopUpExtender id="SendPopUp" and TargetControlID="btnSend"
and
<asp:Panel id="SendPanel">
I get the error as
System.InvalidOperationException: The TargetControlID of '
SendPopUp'is not valid. A control with ID 'btnSend' could not be
found.
How do I make it work?
You need to add the Click event of button then from code behind file you can show model popup by simply write code in button click event
modal.show()
For your reference i am providing you complete code as follow.
I hope it will help you.
<%# Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
<style type="text/css">
.modalBackground
{
background-color: Gray;
filter: alpha(opacity=80);
opacity: 0.8;
z-index: 10000;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<asp:ToolkitScriptManager ID="ScriptManager1" runat="server">
</asp:ToolkitScriptManager>
<div>
<asp:GridView runat="server" ID="gvdetails" DataKeyNames="UserId" AutoGenerateColumns="false">
<RowStyle BackColor="#EFF3FB" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<asp:ImageButton ID="imgbtn" ImageUrl="~/Edit.jpg" runat="server" Width="25" Height="25" onclick="imgbtn_Click" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Designation" HeaderText="Designation" />
</Columns>
</asp:GridView>
<asp:Label ID="lblresult" runat="server"/>
<asp:Button ID="btnShowPopup" runat="server" style="display:none" />
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="btnShowPopup" PopupControlID="pnlpopup"
CancelControlID="btnCancel" BackgroundCssClass="modalBackground">
</asp:ModalPopupExtender>
<asp:Panel ID="pnlpopup" runat="server" BackColor="White" Height="269px" Width="400px" style="display:none">
<table width="100%" style="border:Solid 3px #D55500; width:100%; height:100%" cellpadding="0" cellspacing="0">
<tr style="background-color:#D55500">
<td colspan="2" style=" height:10%; color:White; font-weight:bold; font-size:larger" align="center">User Details</td>
</tr>
<tr>
<td align="right" style=" width:45%">
UserId:
</td>
<td>
<asp:Label ID="lblID" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="right">
UserName:
</td>
<td>
<asp:Label ID="lblusername" runat="server"></asp:Label>
</td>
</tr>
<tr>
<td align="right">
FirstName:
</td>
<td>
<asp:TextBox ID="txtfname" runat="server"/>
</td>
</tr>
<tr>
<td align="right">
LastName:
</td>
<td>
<asp:TextBox ID="txtlname" runat="server"/>
</td>
</tr>
<tr>
<td align="right">
City:
</td>
<td>
<asp:TextBox ID="txtCity" runat="server"/>
</td>
</tr>
<tr>
<td align="right">
Designation:
</td>
<td>
<asp:TextBox ID="txtDesg" runat="server"/>
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnUpdate" CommandName="Update" runat="server" Text="Update" onclick="btnUpdate_Click"/>
<asp:Button ID="btnCancel" runat="server" Text="Cancel" />
</td>
</tr>
</table>
</asp:Panel>
</div>
</form>
</body>
</html>
Code Behind file
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconnection"].ToString());
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
BindGridData();
}
}
protected void BindGridData()
{
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Employee_Details", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
gvdetails.DataSource = dt;
gvdetails.DataBind();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("update Employee_Details set FirstName=#FirstName,LastName=#LastName, City=#City,Designation=#Designation where UserId=#UserId", con);
cmd.Parameters.AddWithValue("#FirstName", txtfname.Text);
cmd.Parameters.AddWithValue("#LastName", txtlname.Text);
cmd.Parameters.AddWithValue("#City", txtCity.Text);
cmd.Parameters.AddWithValue("#Designation", txtDesg.Text);
cmd.Parameters.AddWithValue("#UserId", Convert.ToInt32(lblID.Text));
cmd.ExecuteNonQuery();
con.Close();
lblresult.Text = lblusername.Text + " Details Updated Successfully";
lblresult.ForeColor = Color.Green;
BindGridData();
}
protected void imgbtn_Click(object sender, ImageClickEventArgs e)
{
ImageButton btndetails = sender as ImageButton;
GridViewRow gvrow = (GridViewRow)btndetails.NamingContainer;
lblID.Text = gvdetails.DataKeys[gvrow.RowIndex].Value.ToString();
lblusername.Text = gvrow.Cells[1].Text;
txtfname.Text = gvrow.Cells[2].Text;
txtlname.Text = gvrow.Cells[3].Text;
txtCity.Text = gvrow.Cells[4].Text;
txtDesg.Text = gvrow.Cells[5].Text;
this.ModalPopupExtender1.Show();
}
since your panel if outside of the gridview it wont work this way. add a hiddenfield and set the targetcontrolid to that field. Next in the button click of the gridview use modalpopup.show();

By refreshing gridview using timer, modal popup is automatically closing

Am using a modal pop for a grid view column where the grid view is set with timer.
<asp:UpdatePanel ID="GridPanel" runat="server">
<ContentTemplate>
<asp:Timer ID="autorefresh" runat="server" Interval="5000" />
<asp:GridView ID="SigmaGrid" runat="server" AutoGenerateColumns="False"
onrowcommand="SigmaGrid_RowCommand" CssClass="mGrid" PagerStyle-CssClass="pgr"
AlternatingRowStyle-CssClass="alt" AllowPaging="True"
onpageindexchanging="SigmaGrid_PageIndexChanging">
<AlternatingRowStyle CssClass="alt" />
<PagerStyle />
<Columns>
<asp:TemplateField HeaderText="FirstName" SortExpression="FirstName">
<ItemTemplate>
<asp:LinkButton ID="FirstName" runat="server" Text='<% # Eval("FirstName") %>' CommandName="Select"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle CssClass="pgr" />
</asp:GridView>
<asp:Panel ID="DtlsPanel" runat="server" BackColor="White" Height="400" Width="500px" >
<table style="border: Solid 3px #626262; width: 100%; height: 100%"
cellpadding="0" cellspacing="0">
<tr style="background-color: #626262">
<td colspan="2" style="height: 10%; color: White; font-weight: bold; font-size: larger"
align="center">
Records
</td>
</tr>
<tr>
<td style="color: Black">
First Name:
</td>
<td align="center" style="color: Black">
<asp:Label ID="FNamelbl2" runat="server"></asp:Label>
</td>
</tr>
</table>
</asp:Panel>
<asp:Button ID="btnPopUp" runat="server" Style="display: none" />
<asp:ModalPopupExtender ID="DetailsPopUp1" runat="server" BackgroundCssClass="modalBackground"
TargetControlID="btnPopUp" PopupControlID="DtlsPanel" CancelControlID="btnCancel"
PopupDragHandleControlID="PopupHeader">
</asp:ModalPopupExtender>
</ContentTemplate>
</asp:UpdatePanel>
Code
protected void SigmaGrid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Select")
{
LinkButton FirstName = (LinkButton)e.CommandSource;
GridViewRow row = (GridViewRow)FirstName.NamingContainer;
FNamelbl2.Text = FirstName.Text;
this.DetailsPopUp1.Show();
}
}
Problem
Whne i click on firstname colunn i get a pop up which displays the details of a row.. As i have used timer gridview is refreshed and pop up is automatically closing.
If you're using a ModalPopupExtender with postbacks, you should ensure in codebehind that the popup will be shown. Therefore you can use it's method Show.
For example in the page's or UserControl's PreRender:
C#
protected void Page_PreRender(object sender, System.EventArgs e)
{
if (this.Visible) {
this.DetailsPopUp1.Show();
}
}
VB.NET
Private Sub Page_PreRender(sender As Object, e As System.EventArgs) Handles Me.PreRender
If Me.Visible Then
Me.DetailsPopUp1.Show()
End If
End Sub

How to get text in popup control extender?

i am using a popup control extender.but i am getting only index of selected value from radiobutton list.I want to get the text
Below is my source code
<div class="FloatRight">
<asp:TextBox ID="txtTeam" runat="server" Width="150px" autocomplete="off"></asp:TextBox>
<br />
<asp:Panel ID="panel" runat="server">
<div style="border: 1px outset white; width: 100px">
<asp:UpdatePanel runat="server" ID="up1">
<ContentTemplate>
<asp:RadioButtonList ID="rbteam" runat="server" AutoPostBack="true" OnSelectedIndexChanged="rbteam_SelectedIndexChanged">
</asp:RadioButtonList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
</asp:Panel>
<cc1:PopupControlExtender ID="txtTeam_PopupControlExtender" runat="server" Enabled="True"
and this is server side
protected void rbteam_SelectedIndexChanged(object sender, EventArgs e) {
if (!string.IsNullOrEmpty(rbteam.SelectedValue))
{
txtTeam_PopupControlExtender.Commit(rbteam.SelectedValue);
}
else
{
txtTeam_PopupControlExtender.Cancel();
}
rbteam.ClearSelection();
}
txtTeam_PopupControlExtender.Commit(rbteam.SelectedItem.Text);

Resources