Tuesday, October 27, 2009

Open a new browser tab from ASP.NET control

To open a new browser tab from ASP.NET control client side scripting must be used (not ASP.NET OnClick). There are few answers on the web how to do that. Some don't work & some are incomplete. The following works with any browser version I've checked:

button.Attributes.Add("onclick", "javascript: window.open('your_url','',''); return false;");

This add a client side event handler "onclick", which overrides the ASP.NET OnClick event. If you put both ASP.NET OnClick event handler & this "onlick" client side handler, only the client side will be executed. You may choose if to add the client side handler at run-time.