2

I want to set a textbox.text to a certain value if Request.QueryString['EQCN'] does not exist. If it does exist, I would like to set it to the value of Requestion.QueryString['EQCN'].

It seems that if the value doesn't exist it defaults the value to be "".

Any ideas?

Thanks so much!!!

2 Answers 2

5

If the parameter is not in the query string, the QueryString indexer will return a null reference, so you can use the ?? operator for a default value:

textbox.text = Request.QueryString['EQCN'] ?? "default text";
Sign up to request clarification or add additional context in comments.

Comments

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

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.