Hi,
I have a problem with validating textboxes in EditForm – one of them must be LessThanEqual. Outside aspxgridview it works perfectly.
Can you help me with that?
Best regards
Radek
Standard ASP.NET validatiors / asp:CompareValidator do not work via callbacks
Answers approved by DevExpress Support
Hi Radek,
Thanks for the project. I see the issue. I'd like to note that the asp:CompareValidator.ControlToValidate property requires a Control.ClientID. However, if a control resides in a naming container (grid's EditForm in your situation, or similar), then its Control.ClientID doesn't equal Control.ID. In your case, the ASPxTextBox2.ClientID is formed dynamically.
As a solution, I suggest that you set the CompareValidator.ControlToValidate on the CompareValidator.Init event handler. For example:
Visual BasicProtected Sub CompareValidator1_Init(ByVal sender As Object, ByVal e As System.EventArgs)
Dim CompareValidator1 As CompareValidator = TryCast(sender, CompareValidator)
Dim ASPxTextBox2 As ASPxTextBox = TryCast(grid.FindEditFormTemplateControl("ASPxTextBox2"), ASPxTextBox)
CompareValidator1.ControlToValidate = ASPxTextBox2.ClientID
End Sub
Attached is a modified project.
Thanks,
Marion
Hi Radek,
Thanks for the response. You are right, the Init approach doesn't work. Sorry for my inadvertence. I've discussed this behavior with our developers, and we have the following result for you. The asp:CompareValidator control was developed before the Ajax technology appeared. Therefore, this control can't work via callbacks at all. So, if you want to use the asp:CompareValidator inside the EditForm template, you should set the ASPxGridView.EnableCallBacks property to false. But, I'm afraid that using the asp:UpdatePanel in this case is also undesirable. To learn more, please see:
Validators inside Update Panel don't work properly
Thanks,
Marion
Thanks for reply,
Is there any other way to validate those textboxes inside EditForm - maybe some custom javascript?
Thanks,
Radek
Hi Radek,
If you want to compare two textbox values, you can handle the client-side ASPxClientEdit.Validation Event or server-side ASPxGridView.RowValidating one.
Please refer to the following links where you can find examples of using these events:
How to raise validation on the client side
How to validate EditForm editors
ASPxEditors - Inplace Validation Demo
Thanks,
Marion