0

Is there a way to only update part of the page and update the query string parameters at the same time without completely refreshing the whole page in ASP.NET?

I only need to update the "main" section of my page and not the whole page. I understand I can do a partial page postback (or use asp ajax) to do the partial page update, but then how do I update the query string parameters in the URL at the same time? Is that even possible?

Or is it not possible and I'll have to just do a Response.Redirect in the code behind of the partial page postback redirecting to the same page with new query params and just let the whole page refresh?

johntrepreneur
  • 3,956
  • 4
  • 33
  • 49
  • Do you want to change the actual address the user would be able to copy and paste, or do you just want to change the querystring parameters your page will receive? – Geeky Guy Oct 08 '13 at 18:30
  • @Renan - The actual address so users can copy/paste/share URL. However, all that's changing in the URL is the querystring parameters. – johntrepreneur Oct 08 '13 at 18:33
  • http://stackoverflow.com/a/1468/698202 might be worth a look "Modify Address Bar URL in AJAX App to Match Current State" – geedubb Oct 08 '13 at 18:51
  • You should look into using HTML5 History. See this question for good articles on it: http://stackoverflow.com/questions/4015613/good-tutorial-for-using-html5-history-api-pushstate – Bryan Oct 08 '13 at 18:55

2 Answers2

1

Use pushState.

This new feature offers you a way to change the URL displayed in the browser* through javascript without reloading the page. It will also create a back-button event and you even have a state object you can interact with.

window.history.pushState(“object or string”, “Title”, “/new-url”);

Described here

John Wu
  • 44,075
  • 6
  • 37
  • 69
0

You have absolutely zero programmatic access to the address bar. The only way to change it is to redirect.

You could, however, do it like some sites do and provide a "send a link to this page to your friends" area. Youtube comes to mind - see how it provides a URL, querystring parameters included, for you to copy, should you wish to send someone a link to a video starting from some specific point.

Also check the handy "Share" link right under your question. You could provide a link like that, with the target URL, so for the user it's just a matter of right-clicking and copying from the context menu. A link well structured into your site is more user friendly than having the user copy directly from the bar, or from a text box. Specially for mobile browsers, where the sequence is usually press-and-hold, then copy. Copying from the address bar, on the other hand, may involve selecting the address bar text, which in some Android devices is a pain in the ass.

Geeky Guy
  • 8,658
  • 4
  • 38
  • 60