how to validate the input form of a silverlight control?
I have 3 controls, two out of three are text boxes (For name, and Age), and the remaining one control is date picker.
When i hit submit button, the validation should be invoked. how it will done??
thanks in advance.
If you're using Silverlight 3 check out Data Validation. http://www.silverlightshow.net/items/Data-Validation-in-Silverlight-3.aspx
If you're using Silverlight 2 you'll have to roll your own code for validation.
I wrote my own validaion for SL2. It's based on:
Attached property to give control custom validation ID
Business object validators that identify invalid data
VisualTreeHelper to parse visual tree and match validation result and custom validation ID
Custom templates for controls in order to display validation
INotifyPropertyChanged to remove validation display if property value was changed.
You may also find the Validation Application Block (which is part of the Enterprise Library Silverlight Integration Pack) useful. It's in public preview right now.
Related
This seems like a really simple task to accomplish, but I can't seem to figure it out. How do you assign validation to a particular field in Sitecore?
I can see the validation rules listed in /sitecore/system/Settings/Validation Rules/Field Rules/.
How do I assign a rule from here to a field on a template?
I've seen several blog posts about creating a custom OnSave action that evaluations the item and it's fields - that you then hook up in the web config - but that is way overkill for what I'm trying to accomplish. None of the blog posts or pdfs from Sitecore itself seem to show how to set up really simple validation (or I can't find them).
For some basic validation you can browse to your template, select the field itself (the field item underneath the template, I mean) and browse to the Validation Rules section.
There is also another simple way (did not check if it stil exists in Sitecore 7).
Go to the template field itself, as Trayek says, and therer you have 2 fields: "Validation" and "ValidationText".
In Validation you enter the regex for the validation and in ValidationText you enter the text to display.
Just set validation rule Item id in Suppressed Validation Rules field.
First check the "Standard Fields" checkbox from "view" tab of top ribbon and go on data template of selected item, select field for validation, on this field you can find Validation Rules bar here you can apply validation.
I would not just dump a regex in the validation field. Creating a rule and assigning it on a template affords you a lot more flexability
In my windows application i have a tab control with many tabs and sub tab controls also, each and every tab has many field like text boxes and list boxes.
i thought to validate every field by clicking button called "NEXT" before changing to nexttab and if any field fails with validation a message box should pop-up with error message and focus should remain in that field. can any one help me with ur suggestions...
validation requirements are required field and only numeric and alphanumeric...
Thanks in advance!!!!
A good way is to create a derived controls with input area and validation logic. Then, it is matter of enumerating hierarchy of controls and see if they are valid based on validation rules applied.
Another way, is to "attach" validation logic to controls. How? A mapping mechanism or use the "Tag" property.
But isn't it better to validate control using "Validate" event, when user tries to exit the control? That will not allow user to supply bunch of trash and hope it can be saved.
I've a container (RadDockZone - Telerik), and inside it, a textbox field with an "Asp:RequiredFieldValidator", which makes it mandatory. Every time that I work with AJAX operations, the entire container is "reloaded", including the RequiredFieldValidator. This makes the ValidationSummary show the same error message twice, until the page is completely reloaded (I'm using RadAjaxManager to solve the AJAX operations).
So, how can I "don't reload" a specific control (in this case, the RequiredFieldValidator) using C#?
Regards!
If you place the following in page load if(page.Isvalid) the required field validator will be fired once after submitting that form. The message will not be displayed twice.
If you do not include the textbox (or its wrapping containers) in the list of controls updated by the ajax manager, the textbox and the respective required validator should not be updated on ajax requests and the error message should not be visualized.
You should use validation groups. This lets you group all of your validation controls into a group. Then put this same validation group on your submit button and those validation controls will only validate when that particular button is clicked.
Property is assigned on the validation control and button using the ValidationGroup property.
Thomasvdb's suggestion of setting CausesValidation to false also might be a good way to do it.
How should one handle validation in WPF 4 when there is no binding? Most of the validation doco I am reading seems to be for controls that have bindings.
For example, just a main windows with some text boxes that a user would fill out, and then a button someone would then click on. One could do it manually I guess but wouldn't' there be a WPF approach for this?
(any short code examples would be appreciated)
I think the most WPF solution would be to create a ViewModel you could bind to, then doing the validation there For example if its a change of password form with an additional "confirm password" field, this won't bind directly to a "user" model with just one password field. So instead create a viewModel with 2 fields "password1" and "password2", databind to these two properties and add representation-specific validation here.
How can I prevent the user from entering anything but alpha characters in my textbox?
Update
Forgot to mention that its a dynmic control (created on the form when the user clicks a button).
With built-in ASP.NET features only, you could use the <asp:RegularExpressionValidator> control, with a regular expresion like [A-Za-z]*. This will validate on server side (which should be your main concern), and give a user-friendly error message on postback. There are ways to use these controls for clientside validation as well if you're using the MVC framework, but I don't know how or how well that works in WebForms.
Using jQuery, there are endless possibilities for clientside validation as well with the jquery.validation plugin.
The AjaxControlToolkit has a FilteredTextBox extender that allows you to specify a combination of both lower- and uppercase letters.
I would set a CssClass on the dynamically created textbox, then use jQuery and some custom javascript/regex to filter any input field with that CssClass on the keyup event.
The filtered TextBox extender is good, and you could probably use that as well, for me, the jQuery solution would be a little easier and flexible.