Solved

Server Validate

Posted on 2012-04-07
2
230 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
How to connect to a remote mysql server using C#? 9 43
JavaScript error 1 34
Chat Room 1 29
Visual Studio 2013 debugging 2 21
Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

760 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now