I have Linkbutton in the Gridview TemplateField. I want to Redirect to another Page in a popup Custom size window from RowCommand Event.
Note: Here I don't want to call OnClientScript property of LinkButton to openJavascript Popup Custom Size Window. I want to save Gridrow into Session object and open window from Serverside code only.
Here is the Code:
<ItemTemplate>
<itemstyle width="5%" />
<asp:LinkButton CssClass="l_link" ID="lnkView" runat="server"
DataTextField="overWriteType"
CommandName="overWriteType"
CommandArgument='<%# Eval("overWriteType") %>'
Text='<%# Eval("overWriteType") %>'></asp:LinkButton>
</ItemTemplate>
protected void gvKeys_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "overWriteType")
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("<script language='javascript'>");
sb.Append("window.open('OverwriteConfiguration.aspx', 'PopUp',");
sb.Append("'top=0, left=0, width=500, height=500, menubar=no,toolbar=no,status,resizable=yes,addressbar=no');<");
sb.Append("/script>");
ScriptManager.RegisterStartupScript(Page, GetType(), "OpenWindow", sb.ToString(), true);
}
}
The above code is not opening any window.
You don't want to use RegisterStartupScript in this case, you want to add an onclick handler for your button and you want to do it in RowDataBound instead:
protected void gvKeys_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append("window.open('OverwriteConfiguration.aspx', 'PopUp',");
sb.Append("'top=0, left=0, width=500, height=500, menubar=no,toolbar=no,status,resizable=yes,addressbar=no');<");
LinkButton l = (LinkButton)e.Row.FindControl("lnkView");
l.Attributes.Add("onclick", sb.ToString());
}
}