Open a New Browser Window From an ASP.Net Server Control
All ASP.Net controls add functionality to your web application by performing postbacks to the server. When they post back, their events are captured by the web server. So if you add an onclick event to a button, it will be a server-side event. But what if you need a button to open a window or JavaScript prompt when you click on it? This is a client-side event, and there's no way to add this property to an ASP.Net server control it would seem. Here's the code to allow you to do it programmatically.
Basically, we have to alter the HTML output of the button before the page loads or renders. The easiest way to do this is to add an attribute to the web control. So so we had a button control that looked like this:
<asp:button id="button1" runat="server" onClick="button1_click" />
</form>
The "button1_click" event refers to a method that is run on the server. Here's how to add the JavaScript to create a popup, popunder, alert, or whatever else you need to do on the client side:
{
if (!IsPostBack)
{
button1.Attributes.Add("onclick", "window.open('help.htm', ", ", 'height=200,width=400'");
// or alert user
//button1.Attributes.Add("onclick", "alert('You clicked the button')");
// or whatever
//button1.Attributes.Add("onclick", "anyJavaScriptFunction");
}
}

on May 11th, 2006 at 5:54 am
i want to open window on client machine on button click of main page
let the client select some data from that window
set the selected data to controls on main page
and then i want execute some server code
server code must be excuted after whole client code is executed
on May 11th, 2006 at 11:10 am
I don't really understand what you're asking
on January 27th, 2007 at 4:43 am
hello
on May 11th, 2007 at 7:01 pm
why not just do this in a button_click()?
HyperLink1.Target = "_blank";
HyperLink1.ResolveClientUrl("http://www.cnn.com");
it's a piece of cake!
on July 25th, 2008 at 6:40 pm
Thank you good fellow
Not only giving a nice solution, but explaining the cause of the problems when trying to do it with pure asp.net.
You made my day end happy! wish the same for you every day