1. Put a querystring in my page (on Button1_Click) and
2. To ReWrite that querystring from "domain?country=England&city=London" to "domain/England/London/"
I don't want to Reload the whole page (i want to do it through AJAX - the scriptmanager.addhistorypoint adds to the url address without reloading the whole page).
Please advise how can i accomplish that.
p.s. I tried to use scriptmanager.addhistorypoint for that purpose, but i'm not sure that's the best choice, because of:
A) i understand it's main purpose is to support browser history, not querystrings (it also uses "#&&querystringname=variablevalue", not "?querystringnanem=variablevalue")
B) i don't know how to make url rewriting using scriptmanager.addhistorypoint.
If you take out the update panel and just do a normal post, you will see that the page will actually post directly to the unmapped url. That means your url rewriting is gone after a postback. That probably isn't what you would want, correct? If you implement
a url rewriting scheme that actually changes what the form action is, so that posts go to the mapped url instead, not only will it avoid this issue, but it will work better in general. With this scheme, you have the possibility of the server side thinking
the current request is in a different directory than the browser thinks, so things like ResolveClientUrl may report unusable paths. Any way you look at it, its best to avoid that scenario in the first place, so I recommend you take a look at the url rewriting
post by Scott Guthrie,
I'm using HttpModule for URL rewriting like in the above topic. I implemented the version for IIS and everything works as expected.
My problem is in the process of creating URL (domain.com/name/city/category/) on Button1_Click through AJAX.After i have a link with such URL i can read it easily through the above link URL rewriting technique.
Please, give me a small example how to do that.
p.s. I target .NET Framework 3.5, so i cannot use System.Web.Routing namespace.
Forget about the above post in the topic, I'll try re-write my question:
To create a querystring you normaly do Response.Redirect(myurl);. When i do this in page with ASP.NET UpdatePanels, the whole page reloads, with all the UpdatePanels. If I try to do with within an UpdatePanel it behaves the same way. I want to write to the
url querystring (addressbar) without reloading the whole page. Similar to AsyncPostBackTrigger behaviour with an UpdatePanel.
The only method/approach i see doing this is the ToolkitScriptManager.AddHistoryPoint(string, string). I know this method is not designed for creating querystrings through AJAX, but rather for history points in browser. This method is using "#&&" syntax,
not "?" like in the querystring. Also, it urlencodes the whole querystring (including the slash sign "/").
Yet it appends something after the '#', so page does not reloaded.
If you try to add something like ?, the browser then thinks it a new request, and it does send the request to the server and the page is thus reloaded. It is the browser's behaviour.
The ideal way is to provide the url like "domain/England/London/" with users in the first place, after UpdatePanel updates, rewrite it with
Digitborn.co...
Member
684 Points
450 Posts
ASP.NET AJAX querystring and URL rewrite
Apr 26, 2012 10:48 AM|LINK
Hello,
I'd like to use ASP.NET AJAX to:
1. Put a querystring in my page (on Button1_Click) and
2. To ReWrite that querystring from "domain?country=England&city=London" to "domain/England/London/"
I don't want to Reload the whole page (i want to do it through AJAX - the scriptmanager.addhistorypoint adds to the url address without reloading the whole page).
Please advise how can i accomplish that.
p.s. I tried to use scriptmanager.addhistorypoint for that purpose, but i'm not sure that's the best choice, because of:
A) i understand it's main purpose is to support browser history, not querystrings (it also uses "#&&querystringname=variablevalue", not "?querystringnanem=variablevalue")
B) i don't know how to make url rewriting using scriptmanager.addhistorypoint.
sreejukg
All-Star
28153 Points
4212 Posts
Re: ASP.NET AJAX querystring and URL rewrite
Apr 26, 2012 12:00 PM|LINK
for url rewriting in ASP.Net 4.0, refer this
http://weblogs.asp.net/sreejukg/archive/2010/06/23/routing-in-asp-net-4-0-web-forms.aspx
I recommend you to read the following article to understand how you can achieve partial page postback using Ajax
http://msdn.microsoft.com/en-us/magazine/cc748662.aspx
JQuery would be another choice using which you can load server pages.
http://blog.mediasoft.be/partial-page-refresh-with-ajax-and-jquery/
My Blog
chetan.sarod...
All-Star
66569 Points
11265 Posts
Re: ASP.NET AJAX querystring and URL rewrite
Apr 26, 2012 05:59 PM|LINK
Hi,
Please check the below reference to get Url Rewriting to work with Asp.Net Ajax:
http://blog.angrypets.com/2007/01/aspnet_ajax_and.html
If you take out the update panel and just do a normal post, you will see that the page will actually post directly to the unmapped url. That means your url rewriting is gone after a postback. That probably isn't what you would want, correct? If you implement a url rewriting scheme that actually changes what the form action is, so that posts go to the mapped url instead, not only will it avoid this issue, but it will work better in general. With this scheme, you have the possibility of the server side thinking the current request is in a different directory than the browser thinks, so things like ResolveClientUrl may report unusable paths. Any way you look at it, its best to avoid that scenario in the first place, so I recommend you take a look at the url rewriting post by Scott Guthrie,
http://weblogs.asp.net/scottgu/archive/2007/02/26/tip-trick-url-rewriting-with-asp-net.aspx
Senior Software Engineer,
Approva Systems Pvt Ltd, Pune, India.
Digitborn.co...
Member
684 Points
450 Posts
Re: ASP.NET AJAX querystring and URL rewrite
Apr 26, 2012 06:13 PM|LINK
I'm using HttpModule for URL rewriting like in the above topic. I implemented the version for IIS and everything works as expected.
My problem is in the process of creating URL (domain.com/name/city/category/) on Button1_Click through AJAX. After i have a link with such URL i can read it easily through the above link URL rewriting technique.
Please, give me a small example how to do that.
p.s. I target .NET Framework 3.5, so i cannot use System.Web.Routing namespace.
Digitborn.co...
Member
684 Points
450 Posts
Re: ASP.NET AJAX querystring and URL rewrite
Apr 27, 2012 09:51 AM|LINK
Forget about the above post in the topic, I'll try re-write my question:
To create a querystring you normaly do Response.Redirect(myurl);. When i do this in page with ASP.NET UpdatePanels, the whole page reloads, with all the UpdatePanels. If I try to do with within an UpdatePanel it behaves the same way. I want to write to the url querystring (addressbar) without reloading the whole page. Similar to AsyncPostBackTrigger behaviour with an UpdatePanel.
The only method/approach i see doing this is the ToolkitScriptManager.AddHistoryPoint(string, string). I know this method is not designed for creating querystrings through AJAX, but rather for history points in browser. This method is using "#&&" syntax, not "?" like in the querystring. Also, it urlencodes the whole querystring (including the slash sign "/").
BU XI - MSFT
All-Star
22367 Points
2704 Posts
Microsoft
Re: ASP.NET AJAX querystring and URL rewrite
Apr 30, 2012 07:28 AM|LINK
Hello
One option is that you can try add_endRequest method to change the window's address bar's address by javascript
http://msdn.microsoft.com/en-us/library/bb383810.aspx
Yet it appends something after the '#', so page does not reloaded.
If you try to add something like ?, the browser then thinks it a new request, and it does send the request to the server and the page is thus reloaded. It is the browser's behaviour.
The ideal way is to provide the url like "domain/England/London/" with users in the first place, after UpdatePanel updates, rewrite it with
"domain/England/London/#something"
If you have any feedback about my replies, please contact msdnmg@microsoft.com.
Microsoft One Code Framework