Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

control focus, clear and validation

Posted on 2008-06-10
7
Medium Priority
?
308 Views
Last Modified: 2013-11-19
I have a form with textbox, dropdown and radiobutton controls. When the user submits the data, I need the form to validate the data.

Now, I know I can use alert messages or labels for it; but I want the error messages to be dynamic. What I have done is that I've decided to shwo the error in the textboxes or highlight the controls themselves when the data is wrong or not entered. To do this all for all the controls is a bit tedious though. Is there any "shortcut" method where I can define the color and highlighting for all the controls which contain invalid data?

Secondly, I want that when the user tries to focus on the controls to enter the correct information, all the highlighting and error should disappear. Again, to do this for all the controls is proving to be a bit complicated. Is there any easier method to write the code for the 'disappearing act' for all the controls the user focuses on at once?

I'm using ASP.Net.

I even tried CSS; but being novice, I couldn't really make it work that way.
0
Comment
Question by:digitalZo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 3

Expert Comment

by:NIMTUG_Simon
ID: 21749407
With ASP.Net there are a set of validation controls which you use to do this.

What you do is assign 1 or more validation controls to your page for each control and then if they fail the message associcated to the validation control is shown in the validation summary control.
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21749484
I know there's required validation controls; but I'd like solution for the problem which I posted above. Using ClientID is there any way, I can define one colour for all textbox or dropdown controls?
0
 
LVL 3

Expert Comment

by:NIMTUG_Simon
ID: 21749548
Can I make a suggestion that you don't try and make a UI which can confuse end-users, replacing error input with messages isn't what people are used to.
0
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!

 
LVL 10

Author Comment

by:digitalZo
ID: 21749791
<<<Can I make a suggestion that you don't try and make a UI which can confuse end-users, replacing error input with messages isn't what people are used to.>>

Thanks for the suggestion, but I'm not replacing error input with messages. What I'm doing [or want] is that when the user enters incorrect data and clicks the submit, the error message displays in the control itself. the problem is that i dont want to code this for each and every control.. therefore i was asking whether i can use clientid to code the background color and forecolor of the controls to validate.
0
 
LVL 3

Expert Comment

by:NIMTUG_Simon
ID: 21753907
ClientId is used to find out what the controls id is once it is rendered to html on the browser. You would use this then in Javascript on the client to identify the control.

Are you wanting to do the validation on the client side (using Javascript) or post the values back to the server and check them using your server side code (VB.Net or C#)?

Either way you will have to define a set of css styles and what you do is to change the class attribute on the client side or the CSSStyle property on the server (not both)
0
 
LVL 10

Author Comment

by:digitalZo
ID: 21757139
<<<Are you wanting to do the validation on the client side (using Javascript) or post the values back to the server and check them using your server side code (VB.Net or C#)?>>>

Server side. VB.Net.

<<<
Either way you will have to define a set of css styles and what you do is to change the class attribute on the client side or the CSSStyle property on the server (not both)>>>

I did that. but it doesn't seem to change the style when the data is correct. perhaps because i'm a novice at it and havent coded it properly. can you show me how to do it?

i've used javascript coding when the user focuses on the control after the error is displayed. something like this:
txt_custname.Attributes.Add("onFocus", "this.value=''; this.style.backgroundColor = 'white'; this.style.color = 'black';")

while the server side code is this:
IF Regex.IsMatch(Me.txt_custname.Text, alphabet) = False Then
            'err_label.Visible = True
            'err_label.Text = "Only Alphabets are allowed!!"
            'MsgBox("Only Alphabets are allowed", MsgBoxStyle.Information, "Error Message!!!")
            'SetFocus(txt_custname)

            txt_custname.Text = "Only Alphabets are allowed"
        Else
            txt_custname.BackColor = Drawing.Color.White
            txt_custname.ForeColor = Drawing.Color.Black
        End If
0
 
LVL 10

Accepted Solution

by:
digitalZo earned 0 total points
ID: 21757142
Sorry forgot to add this function:

IF Regex.IsMatch(Me.txt_custname.Text, alphabet) = False Then
            err_color()
            txt_custname.Text = "Only Alphabets are allowed"

End if

 Protected Sub err_color()
        txt_custname.BackColor = Drawing.Color.MistyRose
        txt_custname.ForeColor = Drawing.Color.Red
    End Sub
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this tutorial viewers will learn how to embed custom externally-hosted Google Fonts using the Google Font API in CSS Go to the Google Fonts website at google.com/fonts: Browse or search based on font properties or name to find a suitable font for…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

664 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