Wednesday, March 28, 2012

Why Response.Redirect() opens up a new browser window in AJAX?

I have an AJAX enabled page displayed in amodal dialog, When I click on a button that has a Response.Redirect() code, a new browser window gets opened, which is weird and not the behavior that I expect.

I should note that this page worked properly before adding the AJAX related stuff.

I highly appreciate any insight into this problem.

try use server.transfer


I had already tried the Server.Transfer but I got a client side alert: "Sys.WebForms.PageRequestManagerParserErrorException: The message recieved from the server could not be parsed,..."
Try to navigate to next page in Javascript instead of on Server side. I think this can solve the issue.

hello.

i think the problem is that submitting a page on a popup will open another window by default. you can workaround this by adding an iframe to your popup window which loads the page you need.


Thanks, I think the only workaround to my problem was to use the IFrame in the modal window, but still, I'm wondering why the use of Server.Transfer() caused the error in AJAX, and, why the Response.Redirect() would open up a new window, was I missing somthing or it's just the way AJAX works!

May I ask that Response.Redirect is logical/possible at all during a partial postback (for example in an updatepanel's button click event)?!

Simply move that specific button which yield Response.Redirect outside of the updatepanel, maybe it helps.


Yes, the button which yielded the Response.Redirect() or Server.Transfer() for that matter, was inside the UpdatePanel, I moved it outside the UpdatePanel and my problem was solved. Actually the UpdatePanel was inside a Container UserControl, I think I should make use of UpdatePanel more narrowly focused.

Thank you very much indeed.


response.redirect will be correctly interpreted by the ajax platform. you can check this by using ?a "normal" page. the problem that was happening here was related with modal dialogs and the issue described is not an ajax problem.

server.transfer won't work correctly with ajax and shouldn't be used from controls placed inside the updatepanel. this is understandable because partial postbacks expect to receive a predefined message from the server and whe you do a server.transfer you end up retunring a new page to the user which doesn't conform to the expected message.

So response.redirect works with ajax.

If ajax open the redirected page via javascript (maybe using window.open( ... ) ), that can be a problem.

Modern tabbed browsers are configurable how to treat popup pages from normal links or from javascript (new window, same window, new tab, disable totally javascript popups etc.)

I recommend for Robert to try the page in firefox, and play with advanced firefox settings (type about:config in the address bar, and play with "browser.link.open_newwindow.restriction" and similar settings, you can google for help how it works)

ps:

If the button must be in the updatepanel, maybe it is possible to register a script in the server side which open the new window by javascript (a more controlled way.)


I am also running into this problem and am unable to place the control outside of the Update Panel. I am not clear as to how an IFrame would be implemented. Is it meant that an IFrame should be used in place of the AJAX update panel or in addition to? How would this implementation work specifically?

Thanks for any information in advance.


MaybeScriptManager.RegisterPostBackControl could be used to eliminate this problem in some cases.

So leave your button (which has the codebehind redirect logic) in the updatepanel, but use the RegisterPostBackControl method so it will cause a full normal postback. That way you have a normal redirect, not the ajax client side redirect.


Thanks for the responses.

I did try the following on the control that is being clicked to fire the Redirect:

ScriptManager1.RegisterPostBackControl(this.testButton);

Unfortunately, this still launches a new window during the redirect.

Does anyone have any other ideas as to how i can do this? I would be open to attaching some javascript to the button in order to perform the redirect, however, I have already tried adding the following with no success:

ScriptManager.RegisterClientScriptBlock(this.buttonTest,this.buttonTest.GetType(),"Redirect","window.location = 'http://www.testpage.com'",true);


jriell:

I have already tried adding the following with no success:

ScriptManager.RegisterClientScriptBlock(this.buttonTest,this.buttonTest.GetType(),"Redirect","window.location = 'http://www.testpage.com'",true);

If you choose that way (custom client side redirect), I recommend the following to try:

Put a regular input button, link etc. in the updatepanel, for example:

<input type="button" value="test" onclick="window.location.replace( 'http://www.testpage.com' );" />

If that works, try the script withthe RegisterClientScriptBlock stuff.

No comments:

Post a Comment