1

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.

4 Answers 4

3

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();
}
Sign up to request clarification or add additional context in comments.

1 Comment

accepted this over Toran's just because i had no idea that <asp:HiddenField> existed. always used <input type="hidden" />
0

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

Comments

0

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.

Comments

0

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?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.