Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a URL as follows :

http://localhost:61159/Pages/Dashboard.aspx?id=1

Now when i land on Dashboard page with the above url . i will use the query string id for some purpose and once i am done using it . I want to remove the query string without reloading the page.

http://localhost:61159/Pages/Dashboard.aspx

What I have tried:

I was thinking to use POST method to pass url .
Posted
Updated 21-Jul-16 3:39am

You can use javascript to manipulate the history

<script type="text/javascript">
    window.history.pushState(null, null, '<%=Request.Url.LocalPath%>');
</script>



You'd probably only want to run that code if there was actually a param on the query though. It's the only real solution but it obviously requires js and it doesn't remove the old url, simply injects a new step in the history so the user can "go back" to see the original url with id (and of course refresh, change the id etc).

I'm going to assuming what you really want to do is pass data on the url that the user will never see or can't alter, but I'm afraid that is simply impossible.

Things you shouldn&#39;t spend time doing | The ASP.NET Forums[^]
 
Share this answer
 
Comments
Abrar Kazi 22-Jul-16 2:22am    
Thanks :)
This is not a perfect solution, but it will work
use the below logic and try

C#
protected void Page_Load(object sender, EventArgs e)
{

    string id = Request.QueryString["id"];
    if (!string.IsNullOrEmpty(id))
    {

        Session["id"] = id;
        Response.Redirect("WebForm1.aspx");

    }
    else
    {
        id = Convert.ToString( Session["id"]);

    }
}
 
Share this answer
 
Comments
Abrar Kazi 22-Jul-16 2:22am    
Thanks Karthik
Karthik_Mahalingam 22-Jul-16 4:42am    
welcome abrar

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900