Ticket Q274114
Visible to All Users

Standard ASP.NET validatiors / asp:CompareValidator do not work via callbacks

created 15 years ago

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

Answers approved by DevExpress Support

created 15 years ago (modified 11 years ago)

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 Basic
Protected 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

    Show previous comments (1)
    DevExpress Support Team 15 years ago

      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

      RS RS
      Radoslaw Szerner 15 years ago

        Thanks for reply,
        Is there any other way to validate those textboxes inside EditForm - maybe some custom javascript?
        Thanks,
        Radek

        DevExpress Support Team 15 years ago

          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

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.