views:

459

answers:

4

I have a "showall" query string parameter in the url, the parameter is being added dynamically when "Show All/Show Pages" button is clicked.

I want the ability to toggle "showall" query string parameter value depending on user clicking the "Show All/Show Pages" button.

I'm doing some nested "if's" and string.Replace() on the url, is there a better way?

All manipulations are done on the server.

p.s. Toran, good suggestion, however I HAVE TO USE URL PARAMETER due to some other issues.

A: 

Another dirty alternative could be just to use a hidden input and set that on/off instead of manipulating the url.

Toran Billups
A: 

Would it be too much of an effort just to have the value hard-coded into the URL (I know it's not too nice) with a default value or true then just have

booleanVar = !booleanVar;

run on every page load?

At least that would move away from the need of having nested ifs to manipulate the URL.

chrisntr
A: 

I am not sure based upon the question, but isn't this where HTTPHandlers come to the rescue? Shouldn't you be handling the variable alteration on the object prior to page rendering in this case then?

Ian Patrick Hughes
+2  A: 

Just to elaborate on Toran's answer:

Use:
<asp:HiddenField ID="ShowAll" Value="False" runat="server" />

To toggle your state:

protected void ToggleState(object sender, EventArgs e)
{
    //parse string as boolean, invert, and convert back to string
    ShowAll.Value = (!Boolean.Parse(ShowAll.Value)).ToString();
}
bentford
accepted this over Toran's just because i had no idea that <asp:HiddenField> existed. always used <input type="hidden" />
roman m