02.20
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:PopUpWindow ID="PopUpWindow1" runat="server" OpenOnLoad="false" /> <asp:Button ID="Button1" runat="server" Text="Open Window" OnClick="Button1_Click" />
protected void 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; } protected void 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
BroswerWindow 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.
BrowserWindow.cs (7.56 kb),
PopUpWindow.cs (6.91 kb)
Very nice solution for those who don’t like javascript!