Validation is an easy way of requiring input in a specific text box without much hassle. There is a control called RequiredFieldValidator that automatically checks if a text box has input and will not validate if it doesn’t, preventing the user from submitting blank values. 

1. Open Microsoft Visual Studio.

2. Click File > New > Web Site.

3. Choose Visual Basic as the installed template, select ASP.NET Empty Web Site and click OK.

4.  In the solution explorer panel, right click the project solution and click Add New Item.

5. Make sure Visual Basic is the installed template and select Web Form. Leave the name as Default.aspx and click Add.

6. In the toolbox panel, drag three TextBox items inside the div tags followed by two break lines.

7. In the toolbox panel, drag a Button item below the last set of break tags.
Code Block
Default.aspx
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br /><br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <br /><br />
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <br /><br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
    </div>
    </form>
</body>
</html>

Yes, it is possible to find a good web host. Sometimes it takes a while to find one you are comfortable with. After trying several, we went with Server Intellect and have been very happy thus far. They are by far the most professional, customer service friendly and technically knowledgeable host we’ve found so far.

8. In the toolbox, look in the validation section and drag a RequiredFieldValidator after each text box.

9. Click on RequiredFieldValidator1 and in the properties window look for ‘ControlToValidate’. Click on it and enter TextBox1. Repeat for RequiredFieldValidator2 (enter TextBox2) and RequiredFieldValidator3 (enter TextBox3).

10. For all RequiredFieldvalidators, change the ErrorMessage to ‘*‘ (an asterisk) and change the ForeColor to Red.

11. In the toolbox panel, drag a Label item after the closing button tag and delete it’s text.
Code Block
Default.aspx
Adding a RequiredFieldValidator is easy in ASP.NET
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="*" ControlToValidate="TextBox1"></asp:RequiredFieldValidator>
        <br /><br />
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ErrorMessage="*" ControlToValidate="TextBox2"></asp:RequiredFieldValidator>
        <br /><br />
        <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
        <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ErrorMessage="*" ControlToValidate="TextBox3"></asp:RequiredFieldValidator>
        <br /><br />
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:Label ID="Label1" runat="server"></asp:Label>
    </div>
    </form>
</body>
</html>

Need help with cloud hosting? Try Server Intellect. We used them for our cloud hosting services and we are very happy with the results!

12. Switch to design view of Default.aspx. Double click on Button to bring up the Button1_Click event handler. Basically we are just adding the text value from each text box to the label. We will set Label1.Text equal to each text boxes input.
Code Block
Default.aspx.vb
We add the values of each text box and send them to Label1.Text
Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As ObjectByVal e As System.EventArgsHandles Button1.Click
        Label1.Text = TextBox1.Text + " " + TextBox2.Text + " " + TextBox3.Text
    End Sub

End Class
Save and run the application, it my ask to ‘Modify the Web.config file to enable debugging’, click OK. If a user fails to put text in any of the text boxes, a red asterisk (the RequiredFieldValidator) will appear next to the appropriate text box and the button won’t continue to the event handler until all text boxes have text. When all fields have text and the button is clicked then the label we assigned the text values to will appear next to the button.

                  

I just signed up at Server Intellect and couldn’t be more pleased with my fully scalable & redundant cloud hosting! Check it out and see for yourself.

Experiment with the RequiredFieldValidator, its actually satisfying to see that you require input from a user helping with messy mistakes later on down the road. For instance if you wanted the user to enter a user name, but the field did not require validation, the user could submit a blank entry or one with invalid characters that you would not want. Why not just use a RequiredFieldValidator and make sure it is correct?

WebSite54.zip