tags:

views:

81

answers:

2

Hey SO:

I have a form with four values. If any of them are empty I want to alert the user. Would the best way be to just have 4 separate if...then statements? or is there some sort of a fancy thing that I can do with C# to accomplish this?

thanks!

code

The form in question is a static HTML form:

<form id="form1" action="launch.aspx" method="post" target="_blank" name="form1">
    <input type="hidden" name="ClientID" value="123456" />
    <input type="hidden" name="Password" value="986574321" />
    <input type="hidden" name="PracType" value="001" />
    <input type="hidden" name="Encrypt" value="11258746345" />
</form>
A: 

You can do this in C# on the .aspx.cs page, but I think Kev, is right. The RequiredFieldValidator is the quickest, simplest way to get the desired behavior you want.

By the way, why are all your form items hidden? Are we to assume you're using the control? If you can supply us with some more information, I think we can answer your question more accurately.

osij2is
The form is hidden because this form is auto-generated by a platform application. My directive was to prevent clients from directly accessing this website. We did not want to have to deal with creating a bunch of user accounts (lots of clients), so this was a relatively simple way to get over that obstacle.
Anders
+1  A: 

Request.Form returns a NameValueCollection. You can loop through that collection and check if the value is set, if it's not then you can return the name of the missing field.

ZippyV