I am trying to change change the url of current aspx page to the other url on a click of button. Using Request.Url.AbsoluteUri i can get the url but is it possible to modify?. If yes, what actions will it take i mean will it be a new request or a post back.
Please let me know your views.
Thanks, Mehul makwana
No, it's not possible to modify the URL of the current page from code behind.
When the code runs, a new request or postback is already in progress, so the current page will not exist any more once the new response is complete.
When the page that is currently being created loads in the browser, it's URL will be used instead of the URL of the current page. This URL has already been decided before the request, so you can't change that either.
What you can do is to use the Response.Redirect
method to return a redirection page to the browser with the URL that you want. The browser will then make another request to the server to get the page with that URL.
If you want to change the URL of the page to get without using a redirect, doing it in code behind is too late. You have to change what the button does using client script, so that it requests the new URL directly without doing a postback.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With