I have a "showall" query string parameter in the url, the parameter is being added dynamically when "Show All/Show Pages" button is clicked.
我在url中有一个“showall”查询字符串参数,当单击“显示所有/显示页面”按钮时,动态添加参数。
I want the ability to toggle "showall" query string parameter value depending on user clicking the "Show All/Show Pages" button.
我希望能够切换“showall”查询字符串参数值,具体取决于用户单击“显示所有/显示页面”按钮。
I'm doing some nested "if's" and string.Replace()
on the url, is there a better way?
我正在做一些嵌套的“if's”和url上的string.Replace(),有更好的方法吗?
All manipulations are done on the server.
所有操作都在服务器上完成。
p.s. Toran, good suggestion, however I HAVE TO USE URL PARAMETER due to some other issues.
附: Toran,很好的建议,但由于其他一些问题,我必须使用URL参数。
4 个解决方案
#1
2
Just to elaborate on Toran's answer:
只是详细说明Toran的答案:
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();
}
#2
0
Another dirty alternative could be just to use a hidden input and set that on/off instead of manipulating the url.
另一个脏的替代方案可能只是使用隐藏的输入并设置打开/关闭而不是操纵URL。
#3
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
仅仅将值硬编码到URL(我知道它不太好)的默认值或者真的只是有太多努力
booleanVar = !booleanVar;
booleanVar =!booleanVar;
run on every page load?
在每个页面加载运行?
At least that would move away from the need of having nested ifs to manipulate the URL.
至少这将不再需要嵌套ifs来操纵URL。
#4
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?
我不确定是基于这个问题,但这不是HTTPHandlers来救援的地方吗?在这种情况下,你不应该在页面渲染之前处理对象的变量更改吗?
#1
2
Just to elaborate on Toran's answer:
只是详细说明Toran的答案:
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();
}
#2
0
Another dirty alternative could be just to use a hidden input and set that on/off instead of manipulating the url.
另一个脏的替代方案可能只是使用隐藏的输入并设置打开/关闭而不是操纵URL。
#3
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
仅仅将值硬编码到URL(我知道它不太好)的默认值或者真的只是有太多努力
booleanVar = !booleanVar;
booleanVar =!booleanVar;
run on every page load?
在每个页面加载运行?
At least that would move away from the need of having nested ifs to manipulate the URL.
至少这将不再需要嵌套ifs来操纵URL。
#4
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?
我不确定是基于这个问题,但这不是HTTPHandlers来救援的地方吗?在这种情况下,你不应该在页面渲染之前处理对象的变量更改吗?