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

by jrummell 20. February 2007 13:24

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)

 

Tags: ,

asp.net

Comments

5/29/2008 7:14:32 AM #

Very nice solution for those who don't like javascript!

Janko

Comments are closed

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen | Modified by Mooglegiant

About the author

John is a .Net Web Developer for a manufacturing company in Ohio. In his free time he enjoys web development, the outdoors, and spending time with his wife.

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in  anyway.

© Copyright 2009

Ads By Google