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

Combobox causes validation when EnableLoadOnDemand

9 Answers 209 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jes
Top achievements
Rank 1
Jes asked on 18 Feb 2009, 01:39 AM
I've got a combobox with EnableLoadOnDemand turned on and ShowMoreResultsBox as true.  When I click on the combobox or click to show more results, our validation code gets called.  I've tried setting CausesValidation to false on the combobox, but this does not have any effect.  What can I do?

9 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 19 Feb 2009, 08:17 AM
Hi Jes,

I tried the scenario of RadComboBox with LoadOnDeamnd set to True and using Validator for RadComboBox, and found that its working fine for me. I am not getting the validation when clicking the ShowMoreResults or when clicking the RadComboBox. Could you please provide some additional information about the setup which you tried?

Thanks,
Shinu.
0
Jes
Top achievements
Rank 1
answered on 19 Feb 2009, 03:53 PM
We have a RadComboBox like this...
    <telerik:RadComboBox ID="ddlTelerik" runat="server" EnableLoadOnDemand="true" CausesValidation="false"
         
    </telerik:RadComboBox> 

and a CustomValidator as this...
    <asp:CustomValidator runat="server" ErrorMessage="WOO" OnServerValidate="txtTest_ServerValidate3"></asp:CustomValidator> 
 

our CustomValidator method is...
  Protected Sub txtTest_ServerValidate3(ByVal source As ObjectByVal args As System.Web.UI.WebControls.ServerValidateEventArgs) 
 
 
    End Sub 

I've put a breakpoint on the CustomValidator method.  When I click on the radcombobox, the breakpoint is hit.
0
kmccusker
Top achievements
Rank 1
answered on 19 Feb 2009, 06:01 PM
Hi,

Would setting the ValidationGroup property on the controls that need to be validated by the custom validator (and the validator itself) help?
0
Jes
Top achievements
Rank 1
answered on 19 Feb 2009, 06:05 PM
No, this does not make a difference.  I've put them in different validation groups, the same validation groups, no validation groups, and it always still fires. 
0
kmccusker
Top achievements
Rank 1
answered on 19 Feb 2009, 06:55 PM
I haven't used custom validators a whole lot, but what I do know about them is:
 
  • if you leave the ControlToValidate property blank, the server validation function will fire once per server round trip
  • if ControlToValidate is set, the server event will only fire if the control it's validating has a value

The LoadOnDemand and ShowMoreResultsBox both fire the ItemsRequested server side event. Each time this event is fired, your server side validation event is also being fired. I'm not sure what I can suggest. Hopefully what I wrote here can help you think of a workaround for your validation.

I hope this helps,

Kevin

0
Jes
Top achievements
Rank 1
answered on 19 Feb 2009, 07:02 PM
If I set CausesValidation to false on the combobox, shouldn't the validation NOT fire though?
0
Simon
Telerik team
answered on 23 Feb 2009, 02:51 PM
Hello Jes,

In the attached page the ServerValidate event did not fire at my side as I tested with Telerik.Web.UI v2008.3.1314.

Could you have a look at the page and modify it so that the issue appears?

All the best,
Simon
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
Jes
Top achievements
Rank 1
answered on 24 Feb 2009, 02:53 PM
Not sure how to attach files, but here is the aspx file

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="Default" %> 
 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server"
        </asp:ScriptManager> 
        <div> 
 
                 
            <asp:CustomValidator runat="server" EnableClientScript="False"  
                ErrorMessage="This is an error" onservervalidate="Unnamed1_ServerValidate"></asp:CustomValidator> 
            <telerik:RadComboBox ID="RadComboBox1" runat="server" EnableLoadOnDemand="true" CausesValidation="false"
            </telerik:RadComboBox> 
            <br /> 
            <asp:DropDownList ID="DropDownList1" runat="server"
                <asp:ListItem Value="1">One</asp:ListItem> 
                <asp:ListItem Value="2">Two</asp:ListItem> 
                <asp:ListItem Value="3">Three</asp:ListItem> 
            </asp:DropDownList> 
            <br /> 
            <br /> 
            Selected RadCombo Value = 
            <asp:Label ID="Label1" runat="server" Text="-"></asp:Label> 
            <br /> 
            Selected DropDown Value = 
            <asp:Label ID="Label2" runat="server" Text="-"></asp:Label> 
            <br /> 
            <br /> 
            <asp:Button ID="Button1" runat="server" Text="Postback Try" /> 
            <br /> 
            <asp:Button ID="Button2" runat="server" Text="Transfer to Google" OnClick="Button2_Click" /> 
             
 
        </div> 
    </form> 
</body> 
</html> 
 
and here is the .cs file

using System; 
using System.Web.UI; 
 
using Telerik.Web.UI; 
 
public partial class Default : Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
        if (IsPostBack) 
        { 
            Label1.Text = RadComboBox1.SelectedValue; 
            Label2.Text = DropDownList1.SelectedValue; 
        } 
    } 
 
    protected void Button2_Click(object sender, EventArgs e) 
    { 
        Response.Redirect("http://www.google.com"); 
    } 
    protected void Unnamed1_ServerValidate(object source, System.Web.UI.WebControls.ServerValidateEventArgs args) 
    { 
        args.IsValid = false
    } 

If you breakpoint on the server validate method, it is fired every time, even with CausesValidation="false"
0
Simon
Telerik team
answered on 27 Feb 2009, 01:17 PM
Hi Jes,

Thank you for providing the code.

As I test I compared the behavior of RadComboBox to that of the classic TreeView control.

If you put a classic ASP.NET TreeView which loads its Nodes via AJAX callbacks and expand a Node, the ServerValidate method still fires. This leads to the conclusion that this behavior is inherent to ASP.NET.

In this case, I suggest you put a check for !Page.IsCallback in the ServerValidate event handler to distinguish normal from AJAX (which are the invalid ones) cases.

Should you have any further questions, please feel free to contact us again.

All the best,
Simon
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.
Tags
ComboBox
Asked by
Jes
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jes
Top achievements
Rank 1
kmccusker
Top achievements
Rank 1
Simon
Telerik team
Share this question
or