Asp.net Highlight Textbox On Validation Error
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about javascript validation change textbox color Stack Overflow the company Business Learn more about hiring developers or posting ads with change background and border color of invalid controls when validation fails in asp net us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is
Highlight Textbox On Validation Error Jquery
a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Change Text Box Color using Required Field Validator. No Extender Controls Please up vote
How To Change Textbox Border Color Whenever Validation Fails Using Javascript
23 down vote favorite 13 I need to change color of TextBox whenever its required field validator is fired on Clicking the Submit button asp.net servercontrols requiredfieldvalidator share|improve this question edited Oct 13 '08 at 7:05 paxdiablo 488k1179691416 asked Oct 13 '08 at 6:35 Badmate add a comment| 16 Answers 16 active oldest votes up vote 26 down vote What you can do is register a Javascript function that will textbox border color change javascript iterate through the global Page_Validators array after submission and you can set the background appropriately. The nice thing about this is that you can use it on all of your controls on the page. The function looks like this: function fnOnUpdateValidators() { for (var i = 0; i < Page_Validators.length; i++) { var val = Page_Validators[i]; var ctrl = document.getElementById(val.controltovalidate); if (ctrl != null && ctrl.style != null) { if (!val.isvalid) ctrl.style.background = '#FFAAAA'; else ctrl.style.backgroundColor = ''; } } } The final step is to register the script with the OnSubmit event: VB.NET: Page.ClientScript.RegisterOnSubmitStatement(Me.GetType, "val", "fnOnUpdateValidators();") C#: Page.ClientScript.RegisterOnSubmitStatement(this.GetType(), "val", "fnOnUpdateValidators();"); You'll maintain the proper IsValid status in all of your code behind and it can work with all of your controls. Note: I found this solution from the following blog. I just wanted to document it here in the event the source blog goes down. share|improve this answer edited Oct 18 '12 at 21:31 Bob Kaufman 7,900104787 answered Mar 18 '10 at 18:59 Dillie-O 20.3k1363123 1 I like this solution - one change I made myself is to allow for a control to have multiple validators. Cant edit posts yet so not sure how to go about sharing it. –Dieter G Apr 15 '10 at 2:26
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more
How To Make Textbox Border Red Using Jquery
about Stack Overflow the company Business Learn more about hiring developers or posting jquery validate textbox border red ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack change textbox background color on validation Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Highlight a textbox with red border when it is required up http://stackoverflow.com/questions/196859/change-text-box-color-using-required-field-validator-no-extender-controls-pleas vote 0 down vote favorite I'm using css to highlight a textbox with red border when it is required .garbage[style*=inline] + input, .garbage[style*=inline] + select, .garbage[style*=inline] + textarea { background-color: #ffcccc; border: 1px solid #ff0000; }
Sharepoint Services ASP.Net MVC jQuery Sponsored links CodeDigest Navigation Home Register Login Article Guidelines Submit Article Advertise Support Us Contact Us Technology News No News Feeds available http://www.codedigest.com/Articles/ASPNET/414_Highlight_Input_Controls_when_Validation_fails_in_AspNet_Validator_controls.aspx at this time. Community News No News Feeds available at this time. Highlight Input Controls when Validation fails in Asp.Net Validator controls By Satheesh Babu Posted On Oct 08, 2011 Article Rating: (Login) Average Rating: 5No of Ratings: 1 No of Comments: 4 Print this article. Category: ASP.Net Subscribe to our feed! Highlight Input Controls textbox border when Validation fails in Asp.Net Validator controls Asp.Net control set has a set of validation controls that offers input validations without writing a line of code. Often the functionalities provided by the validation controls are suffice to satisfy the validation requirements in our projects. At times, we may need to have a different behavior when compared to the highlight textbox on Asp.Net validator controls for handling the input validations. One of my previous article Restrict Asp.Net Validator controls to Fire on Page Submit demonstrated customizing the Asp.Net validator controls to fire the validations only on click of submit button using JavaScript. Similarly, let’s see how we can highlight the input control (or the control in ControlToValidate) whenever the validation fails just to make the user to have a quick attention on the control to change its input in order to pass the validations. This approach will provide a better user experience when our input forms have large number of input controls. Once this is in place, the users can identify the input control very easily that have the wrong data in a big input forms since it is highlighted. Something like below, To do this, I will use jQuery library for the client side scripting in this article. I assume you have created a new asp.net project in your visual studio to understand this article. By default, when we use Asp.Net Validator controls the frame