user3580909
user3580909

Reputation: 23

To open a popup window on clicking link button in grid view

In the below code i have a grid view inside grid view i have a link button when i click the link button it should open a popup window .pls help me to do this.

<asp:TemplateField HeaderText="Edit" itemstyle-width="150px">
                            <ItemTemplate>
                                <asp:LinkButton ID="btnEdit" runat="server" CommandName="Edit" Text="Edit" CausesValidation="false"/>
                            </ItemTemplate>    
                        </asp:TemplateField>  

Codebehind:

if (e.CommandName.Equals("Edit"))
 {

                    LinkButton btnView = (LinkButton)e.CommandSource;
 Response.Redirect("NewDocument.aspx?DID=" + lblDocumentID.Text.ToString(), true);
                } 

Upvotes: 0

Views: 22983

Answers (3)

samirprogrammer
samirprogrammer

Reputation: 438

<div>
    <asp:GridView ID="gvDemo" runat="server" AutoGenerateColumns="false">
        <Columns>
            <asp:BoundField DataField="Name" HeaderText="Name" />
            <asp:TemplateField HeaderText="">
                <ItemTemplate>
                    <a href="#" onclick='openWindow("<%# Eval("Code") %>");'>View Details</a>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>
</div>
<script type="text/javascript">
    function openWindow(code) {
        window.open('page.aspx?Code=' + code, 'open_window', ' width=640, height=480, left=0, top=0');
    }
</script>

Upvotes: 0

Jameem
Jameem

Reputation: 1838

Try this..

if (e.CommandName.Equals("Edit"))
{
    ScriptManager.RegisterStartupScript(this, this.GetType(), "onclick", "javascript:window.open(
    'NewDocument.aspx?DID="+lblDocumentID.Text+"','_blank','height=600px,width=600px,scrollbars=1');", true);
} 

Upvotes: 1

TechDo
TechDo

Reputation: 18659

Please try:

if (e.CommandName.Equals("Edit"))
{
    string QueryString="val";
    Page.ClientScript.RegisterStartupScript(GetType(), "", "window.open('Page.aspx?QS=" + QueryString + "','','width=500,height=500');"", true);
} 

Upvotes: 1

Related Questions