Solved

Server Validate

Posted on 2012-04-07
2
236 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 250 total points
ID: 37819804
0
 
LVL 19

Accepted Solution

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

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
System.Security 2 27
Where did System.Data.Objects go? 2 29
Problem!!! 8 33
Convert Select to DropDownListFor MVC 5 2 17
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…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 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