Home > Asp.net, Javascript > Open a New Window On Server Side using Javascript Code in Asp.net

Open a New Window On Server Side using Javascript Code in Asp.net


Normally to open a new window using javascript we write the following code:

// open new window with specified path

function OpenWindow(url)

{
    newwindow = window.open(url, 'mywindow', 'width=500,height=400');  

}

Now In .aspx.cs page or server side to use the javascript window open you have to use the following code

 StringBuilder popupScript = new StringBuilder();
 popupScript.Append("<script language='JavaScript'> window.open('ViewReports.aspx?groupid=" + ddlreportGroup.SelectedValue.ToString() + "&FromDate=" + Convert.ToDateTime(txtDate.Text) + "&Todate=" + Convert.ToDateTime(txtToDate.Text) + "&Report=Rptname" + "', '', 'width=950, height=580,scrollbars,status,menubar=no,resizable,toolbar=no,titlebar=no,location=no');</script>");
// if you are using script manager - update panel then this
 ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), "PopupScript", popupScript.ToString(), false);
//else
Page.RegisterStartupScript("PopupScript", popupScript.ToString());



Advertisements
  1. sara
    January 27, 2010 at 5:04 am

    hi,
    That’s very good.
    It solve my problem.
    thanks.

  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: