Open new window from code-behind
Solution 1
You will need to run javascript on postback
Solution 2
You can use RegisterStartupScript to send a window.open script to run once the page has loaded.
However, this will cause the majority of popup blockers to get in your way.
Solution 3
I think this should work ;-)
Add some javascript to your radio button to open a new blank window before you post back. This makes it so popup blockers won't block your popup, since it's opened in response to a users click. See this link for how to do this part.
Then, allow the postback to happen as normal and on page load, register a startup script to tell your already existing window to go to a new url.
String script = "window.open('popupPage.aspx', 'myPopup')";
ScriptManager.RegisterStartupScript(Page, Page.GetType(), "someId", script, true);
Note that in javascript, when you call
window.open(url, 'myPopup')
if a window already exists with that name it'll return it instead of creating a new window... So your popup won't get blocked!
janhartmann
Hello! I'm Jan Hartmann. With a wide set of skills, I enjoy building awesome, highly effective and performing web- and mobile and applications. http://dk.linkedin.com/in/janhartmanndk
Updated on June 05, 2022Comments
-
janhartmann almost 2 years
I need to open a new window from code-behind on post-back if a specific radio button is selected.
Is there any way to do this?
Thank you.
-
epascarello almost 15 yearsFYI: Pop up blockers will block this window from opening.
-
-
NewXcoder over 10 yearsThis appears to work very well. Thanks for posting this answer long after the other answer was accepted! You saved me a lot of grief.
-
NewXcoder over 10 yearsSee @BradParks answer here for a good idea on how to fool popup blockers.