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

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:

<cc1:PopUpWindowID="PopUpWindow1"runat="server"OpenOnLoad="false"/><asp:ButtonID="Button1"runat="server" Text="Open Window"OnClick="Button1_Click"/>

protectedvoid PageLoad(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 Button1Click(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
BroswerWindow property with it, as shown in PageLoad. 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.

John Rummell

Read more posts by this author.