简体   繁体   English

如果Request.QueryString不存在,则设置ASP.NET变量

[英]ASP.NET Set variable if Request.QueryString does not exist

I want to set a textbox.text to a certain value if Request.QueryString['EQCN'] does not exist. 如果Request.QueryString ['EQCN']不存在,我想将textbox.text设置为某个值。 If it does exist, I would like to set it to the value of Requestion.QueryString['EQCN']. 如果确实存在,我想将其设置为Requestion.QueryString ['EQCN']的值。

It seems that if the value doesn't exist it defaults the value to be "". 似乎如果该值不存在,则默认值为“”。

Any ideas? 有任何想法吗?

Thanks so much!!! 非常感谢!!!

If the parameter is not in the query string, the QueryString indexer will return a null reference, so you can use the ?? 如果参数不在查询字符串中,则QueryString索引器将返回null引用,因此可以使用?? operator for a default value: 默认值的运算符:

textbox.text = Request.QueryString['EQCN'] ?? "default text";
textbox.text = string.IsNullOrEmpty(Request.QueryString["EQCN"]) ? "my value" : Request.QueryString["EQCN"];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM