?
Solved

Server Validate

Posted on 2012-04-07
2
Medium Priority
?
255 Views
Last Modified: 2012-04-11
Hello:

I am trying to validate a textbox by making the backcolor red when the textbox is null. The required field validator works fine.

<asp:TextBox ID="CityText" Width="200px" runat="server" />

<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" Display="Dynamic" ErrorMessage="Required" ControlToValidate="CityText"></asp:RequiredFieldValidator>

<asp:CustomValidator ID="CustomValidator1" runat="server" OnServerValidate="CityText_ServerValidate" ControlToValidate="CityText" ValidateEmptyText="true" Display="Dynamic"></asp:CustomValidator>

        protected void CityText_ServerValidate(object source, ServerValidateEventArgs args)
        {

            if ((CityText.Text == null))
            {
                CityText.BackColor = System.Drawing.Color.Red;
            }

        }
0
Comment
Question by:RecipeDan
2 Comments
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 750 total points
ID: 37819804
0
 
LVL 19

Accepted Solution

by:
Manoj Patil earned 750 total points
ID: 37819866
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question