Using ASP.Net to open a new browser window – Part II, the web control

In this post:


This a follow up to my previous post, Using ASP.Net to open a new browser window – Part I.
There I used a static helper class to register a javascript function to open a new browser window. I’ve scratched the static class and replaced it with a BrowserWindow class and a PopUpWindow WebControl. BrowserWindow simply encapsulates all of the parameters passed to RegisterOpenWindowScript(), and PopUpWindow registers the javascript function and the call to the function.

Here’s an example:

«/span>cc1:PopUpWindowID=”PopUpWindow1”runat=”server”OpenOnLoad=”false”/>«/span>asp:ButtonID=”Button1”runat=”server” Text=”Open Window”OnClick=”Button1_Click”/>

protectedvoid Page_Load(object sender, EventArgs e) { BrowserWindow window = new BrowserWindow( “http://john.rummell.info/blog”, 800, 600); window.Resizable = true; window.Scrollbars = true; PopUpWindow1.BrowserWindow = window; } protectedvoid Button1_Click(object sender, EventArgs e) { PopUpWindow1.OpenWindow(); }

PopUpWindow exposes a few of BrowserWindow’s properties: Width, Height, and Url. For more options, create a BrowserWindow object and set PopUpWindow’s BrowserWindow property with it, as shown in Page_Load. You can use the OpenWindow() method of PopUpWindow to open the window as shown in Button1_Click, or you can set OpenOnLoad to true to have it open when the page loads.