Cannot validate editor in GridView or DetailsView

Last post 05-22-2008, 12:15 PM by GDB. 1 replies.
Sort Posts: Previous Next
  •  05-22-2008, 10:16 AM 40669

    Cannot validate editor in GridView or DetailsView

    I have no problem validating the editor when I incorporate it in a Table control but I can't make it work in a GridView. The result is the error: "Unable to find control id 'CeName' referenced by the 'ControlToValidate' property of 'RequiredFieldValidator1'." I'm guessing I will have to do this with code behind.
     
    Here's the relevant ASPX markup:
     
    Outside GridView and DetailsView:

    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ErrorMessage="You must enter a name." ControlToValidate="CeName"></asp:RequiredFieldValidator>

    Inside GridView:

    <EditItemTemplate>

    <CE:Editor ID="CeName" runat="server" Height="250" Width="100%" AutoConfigure="None"

    BreakElement="Br" Text='<%# Eval("Name") %>'>

    </CE:Editor>

    </EditItemTemplate>

  •  05-22-2008, 12:15 PM 40678 in reply to 40669

    Re: Cannot validate editor in GridView or DetailsView

    Follow Up:
     
    Discovered that it wasn't the editor that was throwing the error but my placement of the RequiredFieldValidator. Should be inside the template rather that at the top of the page. The correct implementation is:

    <InsertItemTemplate>

    <CE:Editor ID="CeNewDescription" runat="server" Height="250" Width="100%" AutoConfigure="Minimal"

    BreakElement="P" Text="Enter Description">

    </CE:Editor>

    <asp:RequiredFieldValidator ID="rqv3" runat="server" ControlToValidate="CeNewDescription" ErrorMessage="You must enter a description." />

    </InsertItemTemplate>

     
    This resolves the error message issue but does not resolve the issue of the user being required to enter a value. In this particular case I have a message "Please overwrite this with a product description." If I simply delete the message and submit the form the RequiredFieldValidator doesn't fire and the form submits with a blank value. Does the editor write the opening and closing tags, e.g. <div></div>, even if nothing is entered in the box? Is there a way to set the editor so that it doesn't write the opening and closing tags (if that it what it's doing) so it doesn't trick the RequiredFieldValidator?
View as RSS news feed in XML