This is a migrated thread and some comments may be shown as answers.

CustomValidator and Telerik component

5 Answers 251 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
B.
Top achievements
Rank 1
B. asked on 24 Apr 2009, 04:22 PM
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.

5 Answers, 1 is accepted

Sort by
0
ManniAT
Top achievements
Rank 2
answered on 26 Apr 2009, 12:17 PM
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
0
B.
Top achievements
Rank 1
answered on 27 Apr 2009, 06:56 AM
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?
0
ManniAT
Top achievements
Rank 2
answered on 27 Apr 2009, 08:10 AM
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
0
B.
Top achievements
Rank 1
answered on 27 Apr 2009, 08:27 AM
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.
0
ManniAT
Top achievements
Rank 2
answered on 27 Apr 2009, 08:51 AM
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
Tags
General Discussions
Asked by
B.
Top achievements
Rank 1
Answers by
ManniAT
Top achievements
Rank 2
B.
Top achievements
Rank 1
Share this question
or