Solved

Server Validate

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

809 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