ASPxGridView: How to use standard validation within an edit form template? - asp.net

I want to use ASP.NET's native validation inside my ASPxGridView's edit form template. I do not want to use DevEx's validation, but instead have standard ASP.NET validators in the edit form that report to a validation summary within the template. Can anyone point me in the right direction with this? Thanks.

Have a look at this in Devexpress' forum:
http://community.devexpress.com/forums/p/67285/228991.aspx
According to this, "Standard ASP.NET validators do not support callbacks. Fortunately, controls of the ASPxEditors suite have their own validation mechanism." So it seems like the standard ASP.NET validators will not work.

By default, the DevExpress ASPxGridView control works via AJAX callbacks.
Standard ASP.NET validators do not work properly inside callback-based containers:
http://www.aspnettricks.com/archives/validators-inside-update-panel-doesnt-work-properly/
http://www.devexpress.com/issue=Q274114
It is possible to switch the ASPxGridView control to a standard postback mode.
Just set the ASPxGridView.EnableCallBack http://documentation.devexpress.com/#AspNet/DevExpressWebASPxGridViewASPxGridView_EnableCallBackstopic property to “false”.
However, (I think) it is better to use built-in DevExpress ASPxEditors validation. You can always get assistance from the DX team.

Related

How ASP.NET 4 validation controls work?

I create new page with lots of validation controls, such as RequiredValidation, RegexValidation and so on. I found out that when I create these validation controls, it seems like it render both client java-script and server validation for me automatically.
I want to know, do I understand correctly or not?
Yep. That is correct. The built-in controls do server side validation (for security) and client side validation (for performance and user experience) for you.
Tip: Don't add these validations to the mark-up, but add them through the code behind, as shown in this blog post, since it keeps your code DRY.

How to trigger ASP.NET client-side validations without submit?

I have a website in ASP.NET (WebForms, NOT MVC) which has a survey form divided in several slides. Each slide has a next button that, obviously does a transition (client-side, not post back or remote request) to the next slide.
In each slide I have several ASP.NET controls with their related validators. I want this validators to be triggered when I click the next button (or maybe when each input loses focus?).
I remembered ASP.NET doing client side validation on lost focus, but maybe I'm wrong... (I quit doing ASP.NET development about 3 years now, so I can't remember)
Thanks
UPDATE:
It would be better to make ASP.NET trigger each validator when the associated control lost focus. I remember ASP.NET doing this (or am I dreaming? =P)
First you need to make sure all of your validators have target controls specified using the "TargetControlID" Attribute on the validators.
Then you can set up a validation group per page and specify the group name in your next button and on the controls themselves.
If you are using regular expression validators you can choose them from this website
To Validate Client Side
If you are using custom validators you can create a client function and specify it on the custom validator using the ClientValidationFunction attribute and by setting EnableclientScript = "true" on the custom validator.
Just be sure your client function has sender and args parameters.
It looks like there's a supplied JavaScript function called Page_ClientValidate which should be callable to check the validation manually from JavaScript. I haven't used it, though, so YMMV.
put all your client-side validators into the same validationgroup and with your 'next' button add the same validation group. When you click the button it will automatically trigger all the validators before it does the post-back.
as to manually triggering the validation...
you might also be able to use ValidatorOnSubmit(). I remember doing this in another project but i'm having a hard time finding the code.
It seems that enabling 'SetFocusOnError' on each validator triggers the validation whenever I try to leave the field.
In short decorate your model, now Data Annotations are supported from Asp.Net 4.5
Check my Answer here..Client side webform validations

Asp.Net required field validation

Hi
I need to validate two fields in an Asp.net form, where the requirements is like any one of them is required. For example, there is Page title and sub-heading input boxes, so any one of them is required. Can I do it using the validation controls Asp.Net provides?
Any kind of help is greatly appreciated. Thanks in advance.
You can use a CustomValidator control (MSDN) in ASP.NET for special situations that are not supported by any one of the other standard validators. It was created for this reason.
Microsoft describes how to create a custom validation function here.
Here's another tutorial on implementing it.
Or if you google for keywords like "creating a custom validator in asp.net" you can pick and choose from various solutions for your own project.
For your case, as an alternative to using a CustomValidator, you could explicitly change whether your required field validators are enabled by using the ValidatorEnable() JavaScript function.
// disable validation control
ValidatorEnable(RequiredFieldValidator1, false);
You can then write custom logic in JavaScript to determine the case in which each validation control is either enabled or disabled, and tie it to one of the (client-side) events of the text boxes (onblur, onchange, onkeyup, etc).
Then, on the server side you can write similar logic to do the same thing by setting the "Enabled" property and put this logic in your button click event before you check the IsValid state.
If all you are doing is conditionally determining when something is required, changing the enabled state is your best bet. Exactly what can be done is documented in ASP.NET Validation In Depth.

Do I need to sanitize input from ASP.NET MembershipProvider controls?

I'm using various ASP.NET controls out of the box such as the CreateUserWizard control, Login control etc... For custom controls, I have sanitized my inputs by making sure they conform to expected values. However, is this required for the controls such as the CreateUserWizard control, or is that handled internally? Do I need to provide any extra server side validation to these controls and, if so, would it be best to do it in the "CreateUserWizardControl_CreatingUser" event?
Thanks
If input is coming from any form, then treat it as suspect. I've included some links here that may help you:
http://www.codersbarn.com/post/2008/11/01/ASPNET-Data-Input-Validation.aspx
If you have request validation enabled then form data with script tags will generate an error automatically.

jQuery Validation plugin and ASP.NET validators Web Forms

I would really like use the jQuery Validation plugin in my ASP.NET Web Forms application (not MVC).
I value jQuery validation for the Richer UI experience I can provide the end user and I have some requirements to highlight the invalid fields using a red border (css).
I value asp.net validators because they run the validations not only on the client but on the server so that I don't open various security vulnerabilities to any user who is clever enough to turn off javascript in their browser.
So I am looking for a nice clean way to integrate these two technologies.
The best I can come up with is to have all ASP.NET validators set to enableclientscript=false and repeat the validation rules on the client in jQuery and on the server as asp.net validators but I can already see some challenges with this approach.
In the end I found the lowest friction way to achieve highlighting with asp.net validators and jquery was not to use the jQuery Validation plugin but to use the simple line of jquery which follows (note that the exact syntax will vary depending on how you layout your forms):
<script type='text/javascript'>
$("input[#type=submit]").click(function() {
$('span.validationerror:hidden').parent().parent().find('input').removeClass('inputError');
$('span.validationerror:visible').parent().parent().find('input').addClass('inputError');
});
</script>
You can use asp.net and jquery validators together with no problem... even on the same control... you just need to set CssClass for the control so that jquery can find it... and then you add OnClientClick="return $('#aspnetForm').valid();" to your submit button(s).
Be sure and include the usual jquery library and jquery.validate.js and add a document ready function of course, etc.
This might help!
http://www.delphicsage.com/home/blog.aspx?d=205
If you are serious about validation, I would look into something like Peter Blum's validators (http://www.peterblum.com/Home.aspx) as they should be able to do everything you want and more. They don't use JQuery, but remember the whole point of JQuery is to save developer time - the end user doesn't know or care whether you are using JQuery or not if the overall effect is the same.

Resources