Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Client-Side Validation to change Textbox Background Color?

Reply
Thread Tools

Client-Side Validation to change Textbox Background Color?

 
 
James Radke
Guest
Posts: n/a
 
      10-14-2003
Hello,

I would like to create some type of client-side validation that will change
the background color of a textbox (say to red with white text) when the
entered data is invalid (i.e. not numeric, not a valid date, etc.)...

I have figured out one way to do that using javascript, and the existing
..NET expressionvalidation controls; however, this requires that I write a
new javascript function for each textbox controls OnChange event that I want
to validate so that I can reference the appropriate textbox control and it's
associated validation control. Additionally this forces me to hardcode the
long .NET generated ID's (i.e. __ctl_ctl0__<id>) - which is kind of a pain.

What I am wondering is if there is a better way that I can do this so that I
don't send the round-trip to the server after they exit each field and still
get the great notification/visual of the background color of the textbox
changing?
Thanks!

Jim


 
Reply With Quote
 
 
 
 
MSFT
Guest
Posts: n/a
 
      10-14-2003
Hi James,

I think you can still use the validator control in ASP.NET, including
RequiredfieldValidator, CompareValidator, RangeValidator,
RegularExpressionValidator, and especially, CustomValidator. You can
specify clientvalidfunction to it. And all these validating is perform with
client script. For more information on ASP.NET validator, you can refer to
this article:

http://msdn.microsoft.com/library/de...us/vbcon/html/
vboriwebformsvalidation.asp


Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
 
tommy
Guest
Posts: n/a
 
      10-14-2003
hello Jim,

to modify textboxes on client, for example the background, you have to
put following to your <asp:textbox>

onblur="this.style.backgroundcolor='#EEEEEE'"
onfocus="this.style.backgroundcolor='#38FAEA'"


best regards


tommy


"James Radke" <(E-Mail Removed)> wrote in message news:<(E-Mail Removed)>...
> Hello,
>
> I would like to create some type of client-side validation that will change
> the background color of a textbox (say to red with white text) when the
> entered data is invalid (i.e. not numeric, not a valid date, etc.)...
>
> I have figured out one way to do that using javascript, and the existing
> .NET expressionvalidation controls; however, this requires that I write a
> new javascript function for each textbox controls OnChange event that I want
> to validate so that I can reference the appropriate textbox control and it's
> associated validation control. Additionally this forces me to hardcode the
> long .NET generated ID's (i.e. __ctl_ctl0__<id>) - which is kind of a pain.
>
> What I am wondering is if there is a better way that I can do this so that I
> don't send the round-trip to the server after they exit each field and still
> get the great notification/visual of the background color of the textbox
> changing?
> Thanks!
>
> Jim

 
Reply With Quote
 
台灣微軟技術處支援部
Guest
Posts: n/a
 
      10-16-2003
Hi James,

As a supply, I attach a sample, to demo how we use a customvalidator
control to change a text box's backgroud color when its text is less than 8
charactors:

<asp:TextBox id="TextBox1" style="Z-INDEX: 101; LEFT: 64px; POSITION:
absolute; TOP: 96px" runat="server"
Width="224px" Height="48px" ></asp:TextBox>
<asp:CustomValidator id="CustomValidator1" style="Z-INDEX: 102; LEFT:
376px; POSITION: absolute; TOP: 104px"
runat="server" Width="192px" Height="32px"
ControlToValidate="TextBox1" ClientValidationFunction="validateLength"
ErrorMessage=""></asp:CustomValidator>


<SCRIPT LANGUAGE="JavaScript">
function validateLength(oSrc, args){
args.IsValid = (args.Value.length >= ;

if (args.Value.length <
document.Form1.TextBox1.style.backgroundColor='#ff ff00';

}

</SCRIPT>


Hope this help,

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
not able to click on background tab and backgrounds in properties to change the background. rex Computer Support 2 12-06-2006 02:26 AM
A Paradise DNS address change? What change? There was no change. Tony Neville NZ Computing 7 09-22-2006 01:02 PM
Change Textbox format when Validation fails in GridView =?Utf-8?B?V2FsdGVy?= ASP .Net 2 01-13-2006 01:41 PM
Textbox background color change impacts border style? ML ASP .Net Web Controls 0 07-19-2005 10:03 AM
Can't change textbox background color Craig Duffy ASP .Net 4 09-10-2004 02:40 AM



Advertisments