Postback Targets

Targeting a postback to a new tab / window.

We should be able to set the target="_black" property of the master .net <form> to target a new browser winodw / tab when posting back.

Below is a Test. Add some chars to the TextBox...

Clicking the button "Test" will render this page in a new tab/window and appends the string \n\n **Inside post back ** to the value of the TextBox.

It's been achived via the simple onClientClick attribute on the button :

 onclientclick="$('form').attr('target', '_blank'); return true;"

This assume you're on a regular .net Web Forms Backend, so there's only the one frame [to rule them all].

There are a number of different ways of acheiving the same result, but this is just to prove that it does execute the button handler and render the results in another UI.


If you need to reload the current screen after the button's action has opened the new tab adding the following to the onClientClick attribute, will re-load the current page after 1 second.

onclientclick="$('form').attr('target', '_blank'); setTimeout(function(){location.href = location.href;}, 1000);return true;"

Re-Fresh after onload.

The example above make the asumption that 1 second is the right timeframe, but you might find it's too long or too short.

It might be better to wait for the new tab to load and then re-load the original page.

This can be achived by using the opener property of the window object, within the global scope.

So within the HTML Content of the new page, include some JavaScript that executes the follwing :

if (window.opener) {
  window.opener.location.href = window.opener.location.href

This will ensure the original page is reloaded, but only once the original button click has completed successfully.

Why location.href, and not location.reload()

If you've have a .net page that has already executed a postback, and one which wasn't an AJAX or XHR or an UpdatePanel using location.reload() causes the previous HTTP POST / postback to be re-executed.

Whereas re-setting location.href with the same value, will only load the via GET therefore it will not re-execute the POSTed form.