I have a page request with a QueryString, say http://www.xyz.net/Orders.aspx?OrderID=1. The page is displayed in a browser. Now there is an asp:LinkButton on the page which should enable the user to open the page without the QueryString (as if he had entered http://www.xyz.net/Orders.aspx directly in the browser's address bar).
I had two ideas:
1) Use the PostBackUrl attribute of the LinkButton:
<asp:LinkButton ID="LinkButton1" runat="server" Text="Select"
PostBackUrl="~/Orders.aspx" />
2) Use "RedirectUrl" in an event handler:
<asp:LinkButton ID="LinkButton1" runat="server" Text="Select"
OnClick="LinkButton1_Click" />
...and...
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("~/Orders.aspx");
}
In both cases the browser's address bar shows http://www.xyz.net/Orders.aspx without the QueryString, as I like to have it. But in the first case the page does not change at all. But it should, because I'm evaluating the QueryString in code-behind and control the appearance of the page depending on whether a QueryString exists or not. The second option works as intended.
If I am not wrong the second option requires an additional roundtrip:
Is this correct at all?
Whereas the first option omits the first two steps in the list above, thus saving the additional roundtrip and resulting in:
But, as said, the result isn't the same.
I'm sure my try to explain the differences between the two options is wrong somewhere. But I don't know where exactly.
Can someone explain what's really the difference? Do I really need this second roundtrip of option (2) to achieve what I want?
Thanks in advance!
Update and solution
The author of the question (me) has proven with this question that he does not understand the difference between HTTP POST and GET. For the solution see my comment in egrunin's answer.
If you don't want to hit the server, why not use a plain HTML control:
function stripQuerystring()
{
return window.location.protocol + "//"
+ window.location.host + window.location.pathname;
}
<input type="button"
onclick="javascript:window.location = stripQuerystring();"
value="Click Me">
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