Archive

Posts Tagged ‘window.open’

Open Asp.net Application in Fullscreen using javascript

December 10, 2009 1 comment

Sometimes, we may have a requirement to open the asp.net application developed, to be opened in full screen mode. To accomplish this, below is the code, in login page, after verifying credentials we redirect user to home page.

So now using javascript, we have to use window.open and its fullscreen properties to open home page as follows:

StringBuilder popupScript = new StringBuilder();

popupScript.Append(“<script language=’JavaScript’> window.name = ‘windowname’;open(”, ‘windowname’); window.close();window.open(‘home.aspx’, ”, ‘fullscreen=yes,status=yes,scrollbars=yes,titlebar=no,addressbar=no’);</script>”);

ScriptManager.RegisterStartupScript(this.Page, Page.GetType(), “PopupScript”, popupScript.ToString(), false);

On Logout, you can write the same script with fullscreen = no

Above code will also bypass the alert message we are getting when redirecting to another page using window.open in javascript.

It will by pass the message prompted

“The Web page you are viewing is trying to close the window” Do you want to close this window?


Advertisements

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

October 24, 2009 1 comment

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());