Friday, January 4, 2008

Showing a Pop-Up Window

Pop-up windows, often used for advertisements and promotions, are a hallmark of the Internet. But ASP.NET doesn't provide any mechanism for showing pop-up windows,
because your code can't interact directly with the client's browser. The only solution is to use JavaScript, which provides the useful window.open() function.
The window.open() function requires three parameters:
  •  The link for the new page.
  • The frame name of the window.
  • A comma-separated string of attributes that will configure the style and size
    of the pop-up window. These can include the height and width attributes
    (with pixel values); the toolbar, menuBar, and scrollbar attributes (set to yes or
    no, depending on whether you want to display these elements); and the resizable
    attribute (set to yes or no, depending on whether you want a fixed or resizable
    window border).
The following C# code defines the JavaScript code for showing the PopUp.aspx web
page in a new window, and registers it to execute immediately upon the page being
posted back the next time.
string popupScript = "<script language='javascript'>" +
"window.open('PopUp.aspx', 'CustomPopUp', " +
"'width=200, height=200, menubar=yes, resizable=no')" +
"</script>";

Page.RegisterStartupScript("PopupScript", popupScript);

No comments:

Post a Comment