开发者

append query string to URL on event (C#)

开发者 https://www.devze.com 2022-12-09 22:19 出处:网络
my client has a website that currently makes requests on a particular event (click, load etc). the website is working well and all but he has a problem with getting the website statistics with Google

my client has a website that currently makes requests on a particular event (click, load etc). the website is working well and all but he has a problem with getting the website statistics with Google Analytics, the reason is, because the website never does a re-direct to a different page, it is all within the same page and no matter what event is loaded in the website(be it a video, tables etc) everything are displayed under the same url

www.somewebsite.com/default.aspx

what I want to开发者_JAVA技巧 achieve is on a particular event, change the url to

www.somewebsite.com/default.aspx?type=abc&id=999

How can I do this,. what is the easiest method to do this? please advise. The whole website is built in C#.

Many Thanks.


Is this event happening on the server or the client?

If it's on the server, you can call Response.Redirect and add your new query string parameter to the current url.

If it's on the client (Javascript), you can set the location property.


If you want to preserve your page's state, try adding your querystring parameter to the form's action parameter in Javascript.

Alternatively, as jeffamaphone suggested, you can change the hash (the part after the # sign) by setting location.hash without posting back to the server.


Actually, you should probably move some of the elements to different pages... this is based on what you said:

because basically all I am doing is hiding and showing elements based on events, if i do a response.redirect, it will reload teh homepage.

If I understand correctly, the user is never redirected to a different page, you are just hiding/unhiding elements from default.aspx based in query strings... correct? the simplest solution will be to split that content into different aspx pages.

0

精彩评论

暂无评论...
验证码 换一张
取 消