2012年3月28日水曜日

Response.Redirect + Ajax ;location.href too do the same

I have to rediraect to the same page by adding a connection string

ie

'Response.Redirect("Aju.aspx?SplashFrom=0")

but i know that Response.Redirect is not Ajax compatible

So i have done the code like bellow

Protected Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

ScriptManager.RegisterStartupScript(UpdatePanel1, Me.GetType(), "redirectMe", "location.href='Aju.aspx?SplashFrom=0';", True)

End Sub

But this code also refreshes the whole page

what can i do to only update the update panel by doing a redirection?

NOTE:Button2 is inside the same update panel so i did not and ant trigger in update panel


Response.Redirect works just fine with Ajax. If you are getting errors when using it, then most likely your web.config is not set up correctly. Response.Write is not compatible with partial-page updates, but that is for totally different reasons.

Now, for what you're trying to do: Even if you use Response.Write, you are going to get a full page refresh because you are navigating to a new page. Any time you load a new page (even if you just change the querystring parameters, you are still loading a new version of the page), you are going to get a full refresh. Only when you are changing the contents of a page, such as the value of controls, can you do partial-page updates.


In that scenario, you probably shouldn't be trying to use a redirect at all (client side or server). If you need to update another UpdatePanel from Button2_Click, you could either make Button2 one of its AsyncPostbackTriggers or you could call UpdatePanel1.Update() in Button2_Click.

If that's not helpful, provide a bit more detail about what you're trying to do.


See you are redirecting to other page, So definately you can get a full refresh page.

If you change any content then it will possible to stop refresh the page


chetan.sarode:

See you are redirecting to other page, So definately you can get a full refresh page.

No, i am redirecting to same page with change in query string


As far as the client (browser) is concerned, that is a new page. It has to reload the page.


gt1329a:

In that scenario, you probably shouldn't be trying to use a redirect at all (client side or server). If you need to update another UpdatePanel from Button2_Click, you could either make Button2 one of its AsyncPostbackTriggers or you could call UpdatePanel1.Update() in Button2_Click.

If that's not helpful, provide a bit more detail about what you're trying to do.

No;my button is inside the one and only one update panel i have.

I am redirecting to the SAME page with change in query string,because i have programed to fetch data from database based on the value in query string .

If i give the value in query string it will become easy to book mark the exact page


Please listen.

Itdoes not matter that you are redirecting to the same page. Any change in the URI will cause the browser to load what it considers to be a different page. It is a new request to the server. It is still a redirect. The page will be reloaded and you will see a visible refresh... no matter what you have in updatepanels... no matter if not a single thing changed on the page. That is how it works.

If I redirect fromhttp://www.mysite.com/mypage.aspx?q=1 tohttp://www.mysite.com/mypage.aspx?q=2, even if I the content does not change and I do nothing with the querystring, it will still cause a refresh.

If you want to use the querystring parameters to allow you to bookmark specific state of the page, that's fine. Just understand that you will have a visible refresh.


To create bookmarkable URLs, use document.hash instead of document.href. This manipulates the anchor of the URL, which you can do without causing a refresh.


could you please show me an example of document.hash

Thanks in advance


I have a similar problem. I cannot Response.Redirect("newpage.aspx") or ScriptManager.RegisterStartupScript(Me.UpdatePanel1, Me.GetType(), "redirectMe", "location.href='newpage.aspx';", True) with a button inside updatepanel. Is there anyway around this?
Please help!

0 件のコメント:

コメントを投稿