CustomValidator and Telerik component

6 posts, 0 answers
  1. B.
    B. avatar
    5 posts
    Member since:
    Apr 2009

    Posted 24 Apr 2009 Link to this post

    Hello.

    I'm having problems adding a custom validator to a textbox inside a Telerik component - I would like to validate the text box ComputernameInsert but I don't get any of the following in the drop-down list of ControlToValidate. What am I doing wrong?

    <asp:CustomValidator runat="server" OnServerValidate="ServerValidation"  />

    <telerik:RadDockZone ID="RadDockZoneComputerDetailsInsertMode" runat="server" Width="552px"
                            BorderStyle="None" MinHeight="" MinWidth="" Visible="False">
                            <telerik:RadDock ID="RadDockComputerDetailsInsertMode" runat="server"
                                Width="550px"
                                DefaultCommands="None" DockHandle="None" Left="" BorderStyle="None"
                                    BorderWidth="0px" EnableTheming="True">
                                <ContentTemplate>
                                    <asp:DetailsView ID="ComputerDetails_InsertMode" runat="server"
                                        AutoGenerateRows="False"
                                        DataSourceID="ComputerDetailsInsertDataSource" DefaultMode="Insert"
                                        HeaderText="Basis-Informationen:"
                                        Width="550px" DataKeyNames="ObjectTreeID"
                                        >
                                        <Fields>
                                            <asp:TemplateField HeaderText="Computername" SortExpression="Computername">
                                                <EditItemTemplate>
                                                    <asp:TextBox ID="ComputernameEdit" runat="server" Text='<%# Bind("Computername") %>'></asp:TextBox>
                                                </EditItemTemplate>
                                                <InsertItemTemplate>
                                                    <asp:TextBox ID="ComputernameInsert" runat="server" MaxLength="15"
                                                        Text='<%# Bind("Computername") %>'></asp:TextBox>
                                                </InsertItemTemplate>
                                                <ItemTemplate>
                                                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("Computername") %>'></asp:Label>
                                                </ItemTemplate>
                                            </asp:TemplateField>
    [...]

    Thanks for any help.

    B.M.

  2. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 26 Apr 2009 Link to this post

    Hi,

    is there some server event which fires (should fire) you server validator?
    A simple sample - here my page:
    <form id="form1" runat="server">  
    <div> 
    <asp:CustomValidator ID="vX" runat="server" onservervalidate="vX_ServerValidate" /> 
    <asp:TextBox ID="txtOne" runat="server" /><br /> 
    <asp:TextBox ID="txtTwo" runat="server" /><br /> 
    <asp:TextBox ID="txtThree" runat="server" /><br /> 
    <asp:Button ID="btnGO" runat="server" Text="GO" onclick="btnGO_Click" /> 
    </div> 
    </form> 
     
    and code behind:
            protected void Page_Load(object sender, EventArgs e) {  
                txtThree.Text = "";  
            }  
     
            protected void vX_ServerValidate(object source, ServerValidateEventArgs args) {  
                txtThree.Text+= " validated ";  
            }  
     
            protected void btnGO_Click(object sender, EventArgs e) {  
                txtThree.Text += " OK ";  
            }  
     
    ServerValidate get's fired when I hit OK (submit my data)  - before there is no reason to validate.
    But (you'll see when you test it) - the output shows " validated OK" - so the validator is called - when I hit the button.

    Regards

    Manfred
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. B.
    B. avatar
    5 posts
    Member since:
    Apr 2009

    Posted 27 Apr 2009 Link to this post

    Thank you for your reply. However, I am not having a problem with the event being fired, my problem is that I don't get the expected list of controls to associate with the validator in the list of ControlToValidate. Any idea anyone?
  5. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 27 Apr 2009 Link to this post

    Hi,

    if you only want to validate that single contorl (you wrote about above) simply place the validator in the content template and set the "controltovalidate" property of the validator.
    If you need more you have to find the controls in the tree - for an example with the FindControl function.


    Regards

    Manfred
  6. B.
    B. avatar
    5 posts
    Member since:
    Apr 2009

    Posted 27 Apr 2009 Link to this post

    Wherever I place the custom validator, I am not able to see the control I wish to link to the validator in the ControlToValidate list. I guess it can be done programatically, but I would like to know if there isn't something else I can do so that I don't have to find the control programmatically. The list I get in ControlToValidate in the UI seems to be a random list of my page controls. It doesn't make sense to me.
  7. ManniAT
    ManniAT avatar
    877 posts
    Member since:
    Nov 2003

    Posted 27 Apr 2009 Link to this post

    Hi,

    try to change your code to something like this:
    <InsertItemTemplate> 
        <asp:TextBox ID="ComputernameInsert" runat="server" MaxLength="15"   
            Text='<%# Bind("Computername") %>'></asp:TextBox> 
            <asp:CustomValidator runat="server" OnServerValidate="Unnamed3_ServerValidate"  ControlToValidate="ComputernameInsert" />   
    </InsertItemTemplate> 
     
    And in code behind you should have something like this:
    protected void Unnamed3_ServerValidate(object source, ServerValidateEventArgs args) {  
        string strIngToAnalyze = args.Value;  
        if (AnalyzeMyString(strIngToAnalyze)) {  
            args.IsValid = true;  
        }  
        else {  
            args.IsValid = false;  
        }  
     
    }  
     
    HTH

    Manfred
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017