?
Solved

Opening a window using a command button in gridview c#

Posted on 2009-05-19
1
Medium Priority
?
600 Views
Last Modified: 2012-05-07
I have a ButtonField in one of my colums of the gridview. And on its click i want to open a window using window.open javascript but for some reason could not open it.   I am attaching my code in the following section. The URL is a path of a video on the server.Any suggestions

<asp:GridView ID="gvVideos" runat="server" BackColor="White" BorderColor="#336666" BorderStyle="Double" BorderWidth="1px" CellPadding="4" GridLines="Horizontal"  AllowSorting=True  Width="65%" OnRowDataBound="gvVideos_RowDataBound" OnRowCommand="gvVideos_RowCommand">
                <FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
            <RowStyle BackColor="#E3EAEB" Font-Names="Verdana" Font-Size="10pt" />
            <EditRowStyle BackColor="#7C6F57" />
            <SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#1C5E55" Font-Bold="True" Font-Names="Verdana" Font-Size="8pt"
                ForeColor="White" HorizontalAlign="Left" />
            <AlternatingRowStyle BackColor="White" Font-Names="Verdana" Font-Size="10pt" />
                <Columns>
                    <asp:ButtonField CommandName="LaunchVideo" Text="Launch Video" />
                </Columns>
             
            </asp:GridView>
 
Code
 
protected void gvVideos_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "LaunchVideo")
        {
 
            string URL="",VideoType="",sScript="";
 
            URL = gvVideos.Rows[int.Parse(e.CommandArgument.ToString())].Cells[5].Text;
            sScript = "<script language=javascript>" + " " + "window.open(" + "\"" + URL + "\"" +
                    ",null," + "\" toolbar=no, menubar=no, directories=no, resizable=yes, location=yes, status=yes, scrollbars=0 " + "\"" +
                    "); window.resizeTo (screen.availWidth, screen.availHeight);window.moveTo(0,0);" + " </script>";
 
            Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Startup", sScript, true);
 
 
 
 
 
        }
    }

Open in new window

0
Comment
Question by:mmalik15
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 3

Accepted Solution

by:
channa_m earned 2000 total points
ID: 24422650
You need set the last parameter of the RegisterClientScriptBlock to false.
Page.ClientScript.RegisterClientScriptBlock(this.GetType(), "Startup", sScript,false);

Open in new window

0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question