When I use Request.Form(“myInput”) and the input field “myInput” is blank, I get a server error.
How do I handle this?
Is there a way to check if “myInput” has not been filled?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Reading from the
Request.Formcollection doesn’t cause an exception neither if the value is an emptry string (which happens if the input field is blank) nor if the field doesn’t even exist.If the input field is blank, you get an empty string when reading from the collection, so to check for that you just check if the value of the
Lengthproperty of the string is zero.If the input field doesn’t exist, you get a null reference (
Nothingin VB) when reading from the collection, so to check for that you compare the reference tonull(useis Nothingin VB).To check for both conditions you can use the
String.IsNullOrEmptymethod.