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

Custom Validator ignored in a Rad Window

3 Answers 115 Views
Window
This is a migrated thread and some comments may be shown as answers.
Sam Bronchetti
Top achievements
Rank 1
Sam Bronchetti asked on 05 Jun 2009, 06:37 PM
I have a radwindow that has both Required Field Validators and A Custom Validator.  The required field validators fire and are handled correctly.  The custom validator also fires, but the result is ignored.  I have the following relevant code:
In the calling page:

 

Javascript to open the RadWindow
function
launchEditProjectType(projecttypeid) {

 

var URL = "wfrmAddProjectType.aspx?projecttypeid=" + projecttypeid

window.radopen(URL,

"AddProjectType");

 

 

 

return false;  

}

 

 

<telerik:RadWindowManager ID="winMgr" runat="server" Modal="True" Skin="Web20" Left="" NavigateUrl="" EnableEmbeddedScripts="true" KeepInScreenBounds="true" Height="550px" Width="610px" Behaviors="Move,Maximize,Close">

 

 

 

<Windows>

 

 

 

 

<telerik:RadWindow runat="server" ID="editActivity" VisibleStatusbar="False" Skin="Web20" ReloadOnShow="True" Modal="true" Behaviors="Move,Maximize,Close" />

 

 

 

<telerik:RadWindow runat="server" ID="editProjectType" Height="700px" Width="740px" Behaviors="Close" VisibleStatusbar="False" Skin="Web20" ReloadOnShow="true" Modal="true">

 

 

</telerik:RadWindow>

 

 

</Windows>

 

 

 

</telerik:RadWindowManager>

In the rad window:

<asp:TextBox ID="txtDescription" runat="server" Font-Names="Arial" Font-Size="12px" MaxLength="40" Width="256px" CausesValidation="true"></asp:TextBox 

 

 

<asp:CustomValidator ID="cv2" ControlToValidate="txtDescription" runat="server" Display="Dynamic" OnServerValidate="ValidateProjectType" Font-Bold="true" Font-Names="Arial" Font-Size="20px"

 

 

 

ErrorMessage="CPE Year must be unique" SetFocusOnError="true">*</asp:CustomValidator>

 

 

 

<asp:RequiredFieldValidator ID="rfv0" runat="server" ControlToValidate="txtDescription"

 

 

ErrorMessage="Description" Font-Names="Arial" Font-Size="12px">*</asp:RequiredFieldValidator>

in the .vb codebehind 


Public
Sub ValidateProjectType(ByVal sender As Object, ByVal args As ServerValidateEventArgs)

 

Dim a As Boolean = True

 

 

 

 

If args.Value() <> "" Then

 

 

Dim data As New AdminData

 

 

a =

Not data.isDuplicateProjectType(Me.txtDescription.Text, Me.lblProjectTypeID.Text)

 

 

 

Else

 

a =

False  

 

 

End If

 

 

 

args.IsValid = False

 

 

 

 

 

End Sub

If all validation works, it will try to save.  As you can see, I set the custom validator to always fail, yet it tries to save every time.  If I don't run this code in a rad window, but in a browser on its own, the validation is fine.

Any  thoughts?

 

 

 

 

3 Answers, 1 is accepted

Sort by
0
Fiko
Telerik team
answered on 09 Jun 2009, 07:27 AM
Hi Sam,

We are not quite sure that we understood your requirement and we need your further cooperation. We already answered to your support thread and you can write back and attach files in that thread.

Kind regards,
Fiko
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
GP
Top achievements
Rank 1
answered on 07 Mar 2011, 03:07 AM
Is there an answer to this question?  I am having a similar issue.  I have a radgrid that uses a radwindow for adding records.  This radwindow has a datepicker and a radeditor in it.  I have a requiredfieldvalidator on both of these controls.  I also have a custom validator on the radeditor to check for "&nbsp;" as being the only thing in the content.  (I'm trying to prevent folks from just putting in a space for text.  (" ").  I have tested this code, and the arguments.IsValid returns back false, but still closes the window and adds the record to the database anyway.

I am going to write some server side code that stops the insert and closing the window, but I was hoping to have a clientside validator that stopped it too.

The required validators work like they are supposed to, but the custom one fails as described above.  Here is my source code:
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="AddComment.aspx.vb" Inherits="ARRA.AddCommentUser" %>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 
<head runat="server">
    <title></title>
    <link rel="stylesheet" href="../Style/style.css" type="text/Css" />
    <style type="text/css">
        html, body, form
        {
            height: 100%;
            padding: 0;
            margin: 0;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
            <script type="text/javascript">
                function CloseAndRebind() {
                    GetRadWindow().BrowserWindow.refreshGrid();
                    GetRadWindow().close();
                }
 
                function GetRadWindow() {
                    var oWindow = null;
                    if (window.radWindow) oWindow = window.radWindow; //Will work in Moz in all cases, including clasic dialog
                    else if (window.frameElement.radWindow) oWindow = window.frameElement.radWindow; //IE (and Moz as well)
 
                    return oWindow;
                }
 
                function CancelEdit() {
                    GetRadWindow().close();
                }
                            
                function checkLength(source, args) {
                    //Note that sender is NOT the RadEditor. sender is the span of the validator.
                    //The content is contained in the args.Value variable
                    var editorText = args.Value;
                    var limitNum = 6;
                     
                    //arguments.IsValid = editorText.length > limitNum;
                    if (editorText.length > limitNum && editorText != " ")
                        arguments.IsValid = true;
                    else
                        arguments.IsValid = false;
                }
        </script>
    <div id="art-page-background-gradient">
    <div style="background-image:url('../images/sheet_c.png');height:100%">
       <asp:Table ID="Table1" runat="server">
            <asp:TableRow ID="tr1">
                <asp:TableCell ColumnSpan="2">
                    <asp:Label ID="lblNone" runat="server"></asp:Label>
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow ID="tr2">
                <asp:TableCell>
                    <asp:Label ID="Label1" runat="server" Text="Comment Date"></asp:Label>
                </asp:TableCell>
                <asp:TableCell>
                    <telerik:RadDatePicker ID="cmDate" Runat="server" DateInput-EmptyMessage="Select a Date" Skin="WebBlue" >
                    </telerik:RadDatePicker>
                    <asp:RequiredFieldValidator ID="PickerRequiredFieldValidator" runat="server" Display="Dynamic"
                    ControlToValidate="cmDate" ErrorMessage="Please select a date" ForeColor="Black" Font-Bold="True" Font-Italic="True" />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow ID="tr3">
                <asp:TableCell>
                    <asp:Label ID="Label2" runat="server" Text="Comment"></asp:Label><br />
                    <asp:RequiredFieldValidator ID="TextBoxRequiredFieldValidator" runat="server" Display="Dynamic"
                    ControlToValidate="txtComment" ErrorMessage="Must Enter Comment" ForeColor="Black" Font-Bold="True" Font-Italic="True" />
                    <br />
                    <asp:CustomValidator ID="Customvalidator2" runat="server" Display="Dynamic"
                            ClientValidationFunction="checkLength" ForeColor="#FFFF66" ControlToValidate="txtComment">
                            <span style="FONT-SIZE: 12px;">Need more than a space.</span>
                        </asp:CustomValidator>
                </asp:TableCell>
                <asp:TableCell>
                    <telerik:RadEditor ID="txtComment" runat="server" Skin="WebBlue" Height="200px" Width="550px" EnableResize="False">
                        <CssFiles>
                            <telerik:EditorCssFile value="~Style/EditorContentArea.css" />
                        </CssFiles>
                        <Tools>
                            <telerik:EditorToolGroup Tag="MainToolbar">
                                <telerik:EditorTool Name="FindAndReplace" />
                                <telerik:EditorSeparator />
                                <telerik:EditorSplitButton Name="Undo">
                                </telerik:EditorSplitButton>
                                <telerik:EditorSplitButton Name="Redo">
                                </telerik:EditorSplitButton>
                                <telerik:EditorSeparator />
                                <telerik:EditorTool Name="Cut" />
                                <telerik:EditorTool Name="Copy" />
                                <telerik:EditorTool Name="Paste" ShortCut="CTRL+V" />
                            </telerik:EditorToolGroup>
                            <telerik:EditorToolGroup Tag="Formatting">
                                <telerik:EditorTool Name="Bold" />
                                <telerik:EditorTool Name="Italic" />
                                <telerik:EditorTool Name="Underline" />
                                <telerik:EditorSeparator />
                                <telerik:EditorSplitButton Name="ForeColor">
                                </telerik:EditorSplitButton>
                                <telerik:EditorSplitButton Name="BackColor">
                                </telerik:EditorSplitButton>
                                <telerik:EditorSeparator />
                                <telerik:EditorDropDown Name="FontName">
                                </telerik:EditorDropDown>
                                <telerik:EditorDropDown Name="RealFontSize">
                                </telerik:EditorDropDown>
                            </telerik:EditorToolGroup>
                        </Tools>
                        <Content>
                        </Content>
                    </telerik:RadEditor>
                    <br />
                </asp:TableCell>
            </asp:TableRow>
            <asp:TableRow ID="tr4">
                <asp:TableCell ColumnSpan="2">
                    <asp:Button ID="Button1" runat="server" Text="Add Comment" />
                       
                    <asp:Button ID="Button2" runat="server" Text="Cancel" CausesValidation="false" />
                </asp:TableCell>
            </asp:TableRow>
        </asp:Table>
 
                         
        <telerik:RadFormDecorator ID="RadFormDecorator1" Runat="server"
            Skin="WebBlue" />
      <telerik:RadScriptManager ID="RadScriptManager1" Runat="server">
    </telerik:RadScriptManager>
</div>
    </div>
    </form>
</body>
</html>


Thank you.  Hope you all have a good Monday.
0
GP
Top achievements
Rank 1
answered on 07 Mar 2011, 07:53 PM
Nevermind.  arguments.IsValid should be args.IsValid.
Tags
Window
Asked by
Sam Bronchetti
Top achievements
Rank 1
Answers by
Fiko
Telerik team
GP
Top achievements
Rank 1
Share this question
or