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

Custom validator failure within a RadAjaxPanel

5 Answers 153 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Boris
Top achievements
Rank 1
Boris asked on 28 Apr 2014, 05:39 PM
Will a standard custom validator work within a RadAjaxPanel?

I have a screen with a RadSplitter containing multiple radcombo boxes, custom validators, and the usual javascript code for the validators

Until now they've been working perfectly.

I've just enclosed the entire splitter in a RadAjaxPanel.  

All the server-side code is working normally but the custom validators appear to have failed completely.  The Javascript functions are not being called.  

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Apr 2014, 06:39 AM
Hi Boris,

Please have a look into the sample code snippet which works fine at my end.

ASPX:
<telerik:RadAjaxPanel ID="radajaxpnlCustomValidator" runat="server">
    <telerik:RadSplitter ID="RadSplitter1" runat="server">
        <telerik:RadPane ID="RadPane1" runat="server">
            <telerik:RadComboBox ID="radcboValidate" runat="server" EmptyMessage="select">
                <Items>
                    <telerik:RadComboBoxItem Text="Item1" />
                    <telerik:RadComboBoxItem Text="Item2" />
                    <telerik:RadComboBoxItem Text="Item3" />
                </Items>
            </telerik:RadComboBox>
            <asp:CustomValidator ID="cvalcboValidate" runat="server" ValidationGroup="Group1" ValidateEmptyText="true" EnableClientScript="true" ClientValidationFunction="ValidateCombo">
            </asp:CustomValidator>
            <telerik:RadButton ID="radbtnValidateCombo" AutoPostBack="false" runat="server" Text="Validate" ValidationGroup="Group1">
            </telerik:RadButton>
        </telerik:RadPane>
    </telerik:RadSplitter>
</telerik:RadAjaxPanel>

JavaScript:
<script type="text/javascript">
    function ValidateCombo(args) {
        alert("Event Fired");
        //your code for validating ComboBox
    }
</script>


Please provide your code if it doesn't help.
Thanks,
Shinu.
0
Boris
Top achievements
Rank 1
answered on 29 Apr 2014, 04:00 PM
I'm lost.  I took the advise of another appender to change my save button to SingleClick mode and now it looks like my main problem is that my entire radcombo box validation scheme is failing.  I've verified that it's happening in more than one validator.  I never reach the save button code behind click event. The correct values are definitely getting into the combo boxes but my usual code (the get_value call) is failing, returning a blank.  This is a code pattern I've been using for as long as I've used Telerik.

(I should also mention that my javascript block is outside the RadAjaxPanel.  My usual practice up until now has been to enclose all script in a RadCodeBlock.  I don't know if that affects anything.    )

Here is the declaration for a combo box, its validator, and the save button.

<telerik:RadComboBox ID="ddlUrg" runat="server" DataMember="UrgencyLevelId" DataTextField="UrgencyDesc" Height="200px"
   DataValueField="UrgencyLevelId" Label="Urgency" Font-Size="Large" Skin="Simple" Width="225px" Font-Names="Arial">
</telerik:RadComboBox>

<asp:CustomValidator Visible="true" ClientValidationFunction="validateUrgency" ID="cvUrg" runat="server" EnableClientScript="true"
       ControlToValidate="ddlUrg" ErrorMessage="An Urgency Level Must Be Assigned" Font-Bold="True" ForeColor="Red"
       ValidateEmptyText="True" SetFocusOnError="True" >*</asp:CustomValidator>

<telerik:RadButton ID="btnSave" runat="server" Text="Save" AutoPostBack="true" CausesValidation="true"  OnClick="btnSave_Click" SingleClick="True" SingleClickText="test"></telerik:RadButton>

The Javascript 

 function validateUrgency(sender, args) {
   var comboUrg = $find("<%= ddlUrg.ClientID %>");
   args.IsValid = false;
   if (comboUrg != null)
      if (comboUrg.get_value() != "-1" && comboUrg.get_value() != "")
         args.IsValid = true;
   }
0
Shinu
Top achievements
Rank 2
answered on 30 Apr 2014, 05:32 AM
Hi Boris,

Please do the following modification in your code snippet which works fine at my end.

ASPX:
<telerik:RadAjaxPanel ID="radajaxpnlCustomValidator" runat="server">
    <telerik:RadSplitter ID="RadSplitter1" runat="server">
        <telerik:RadPane ID="RadPane1" runat="server">
            <telerik:RadComboBox ID="ddlUrg" runat="server" Height="200px" Label="Urgency" Font-Size="Large" Skin="Simple" Width="225px" Font-Names="Arial" EmptyMessage="select">
                <Items>
                    <telerik:RadComboBoxItem Text="Item1" Value="1" />
                    <telerik:RadComboBoxItem Text="Item2" Value="2" />
                    <telerik:RadComboBoxItem Text="Item3" Value="3" />
                </Items>
            </telerik:RadComboBox>
            <asp:CustomValidator Visible="true" ClientValidationFunction="validateUrgency" ID="cvUrg" runat="server" EnableClientScript="true" ErrorMessage="An Urgency Level Must Be Assigned" Font-Bold="True" ForeColor="Red" ValidateEmptyText="True" SetFocusOnError="True">*</asp:CustomValidator>
            <telerik:RadButton ID="btnSave" runat="server" Text="Save" AutoPostBack="true" CausesValidation="true" SingleClick="True" SingleClickText="test" OnClick="btnSave_Click">
            </telerik:RadButton>
            <asp:TextBox ID="TextBox1" runat="server">
            </asp:TextBox>
        </telerik:RadPane>
    </telerik:RadSplitter>
</telerik:RadAjaxPanel>

JavaScript:

<script type="text/javascript">
    function validateUrgency(sender, args) {
        var comboUrg = $find("<%= ddlUrg.ClientID %>");
        args.IsValid = false;
        if (comboUrg.get_selectedItem() != null)
            if (comboUrg.get_selectedItem().get_value() != "-1" && comboUrg.get_selectedItem().get_value() != "")
                args.IsValid = true;
    }
</script>

C#:
protected void btnSave_Click(object sender, EventArgs e)
{
    TextBox1.Text = "Fired";
}

Thanks,
Shinu.
0
Boris
Top achievements
Rank 1
answered on 30 Apr 2014, 01:04 PM
So far, no good.

The get_selectedItem().get_value() seems to be working but validation as a whole is still failing.  

SingleClick does not work at all.  The button never gets disabled and the server click event is never called, no matter what the condition of the dropdowns.  The Validation summary never displays.  

If I set SingleClick to false, the click event is always reached, regardless of the condition of the validators, and Page.IsValid is always true.  

I wonder if I have to try server-side validation.  

(I'd like to remind you that all of this except the JavaScript code is inside RadPanes inside a RadSplitter inside a RadAjaxPanel.  I have no idea how many bugs/unknowns I'm dealing with.)

0
Boris
Top achievements
Rank 1
answered on 30 Apr 2014, 01:32 PM
P.S.  It looks like server-side validation is the way to go.  It works perfectly and the validation summary always displays correctly.

Then in the save button click event I simply set the button to disabled if IsValid=true.
Tags
Ajax
Asked by
Boris
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Boris
Top achievements
Rank 1
Share this question
or