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

ComboBox wrapped in Server Control causes validation when it shouldn't

7 Answers 73 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
iTools
Top achievements
Rank 1
iTools asked on 21 Jul 2010, 03:23 AM
Even though it makes the title of this thread invalid, I have simplified the problem in the next post...

7 Answers, 1 is accepted

Sort by
0
iTools
Top achievements
Rank 1
answered on 21 Jul 2010, 04:08 AM
Even given a simpler scenario I get unexpected results.

<asp:ScriptManager ID="ctlScriptManager" runat="server" />
<telerik:RadComboBox ID="ddlCombo" runat="server" AllowCustomText="true">
    <Items>
        <telerik:RadComboBoxItem Text="Item 1" Value="1" />
        <telerik:RadComboBoxItem Text="Item 2" Value="2" />
        <telerik:RadComboBoxItem Text="Item 3" Value="3" />
    </Items>
</telerik:RadComboBox>
<asp:CustomValidator ID="ctlValidator" runat="server" ControlToValidate="ddlCombo"
    ErrorMessage="Please select a predefined item" />
<br />
<asp:Button ID="btnCausePostBackWithoutValidation" runat="server" Text="Post Back w/o Validation"
    CausesValidation="false" />

Private Sub ctlValidator_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs) Handles ctlValidator.ServerValidate
    Dim selectedID As Integer
    If Not Integer.TryParse(ddlCombo.SelectedValue, selectedID) Then
        args.IsValid = False
    Else
        args.IsValid = selectedID > 0
    End If
End Sub

In this scenario I would never expect the validator to be called. Yet, if text is typed in the combo and the button is clicked the validator is called. The only time the validator is not called, as expected, is when no custom text is typed in the ComboBox.

Please advise.
Thanks.
0
Kalina
Telerik team
answered on 26 Jul 2010, 05:15 PM
Hello jan fischer,

The issue that you describe is very strange.
I used your code to create a test page. After running the page and testing it with our latest version (Telerik.Web.UI 2010.2.713.20) under Internet Explorer and Firefox, I can say that the CustomValidator control never fires on my side.
Please find the sample attached and give it a try. Maybe I miss something?

Greetings,
Kalina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
iTools
Top achievements
Rank 1
answered on 26 Jul 2010, 09:39 PM
Hello Kalina,

Your sample is flawed, as the validator is not hooked-up to the ServerValidate event handler.

After changing the ServerValidator event handler to ...
Private Sub ctlValidator_ServerValidate(ByVal source As Object, ByVal args As ServerValidateEventArgs) Handles ctlValidator.ServerValidate
    Dim selectedID As Integer = 0
    If Not Integer.TryParse(ddlCombo.SelectedValue, selectedID) Then
        args.IsValid = False
    Else
        args.IsValid = selectedID > 0
    End If
End Sub
... the unexpected validation behaviour is still observed. I am using the latest Telerik.Web.UI for testing purposes.

Cheers
0
Accepted
Kalina
Telerik team
answered on 30 Jul 2010, 06:00 AM
Hi jan fischer,

Please excuse my omission.
I reproduced the issue and it is really strange.
Let me suggest you set the ValidationGroup property of the RadComboBox and Button :
<telerik:RadComboBox ID="ddlCombo" runat="server"
    AllowCustomText="true" ValidationGroup="test">
    <Items>
        <telerik:RadComboBoxItem Text="Item 1" Value="1" />
        <telerik:RadComboBoxItem Text="Item 2" Value="2" />
        <telerik:RadComboBoxItem Text="Item 3" Value="3" />
    </Items>
</telerik:RadComboBox>
<asp:CustomValidator ID="ctlValidator" runat="server"
    ControlToValidate="ddlCombo"
    ErrorMessage="Please select a predefined item" />
<br />
<asp:Button ID="btnCausePostBackWithoutValidation" runat="server"
    Text="Post Back w/o Validation"
    CausesValidation="false" ValidationGroup="test"
    OnClick="btnCausePostBackWithoutValidation_OnClick" />
    <asp:Label ID="lblTest" runat="server"></asp:Label>

If the issue persists - could you please explain in more details the scenario that you are trying to implement?

Best wishes,
Kalina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
iTools
Top achievements
Rank 1
answered on 01 Aug 2010, 09:02 PM
Hello Kalina,

That does seem to circumvent the unexpected behaviour, however it seems like a bug?
Now, I stuck another button on the form, one that should cause validation.

<asp:ScriptManager ID="ctlScriptManager" runat="server" />
<telerik:radcombobox id="ddlCombo" runat="server" allowcustomtext="true" emptymessage="Please Select"
    onclientdropdownopening="OnClientDropDownOpening" enableloadondemand="true" validationgroup="test" />
<asp:CustomValidator ID="ctlValidator" runat="server" ControlToValidate="ddlCombo"
    ErrorMessage="Please select a predefined item" />
<br />
<asp:Button ID="btnCausePostBackWithoutValidation" runat="server" Text="Post Back w/o Validation"
    CausesValidation="false" ValidationGroup="test" />
<asp:Button ID="btnCausePostBackWithValidation" runat="server" Text="Validate" />

It would seem that expected behaviour would mean the validation handler is called when the btnCausePostBackWithValidation button was pressed without changing the RadCombo control, but the validator is not called. Only a change of the RadCombo causes validator to fire...

Cheers,
Jan
0
T. Tsonev
Telerik team
answered on 05 Aug 2010, 01:35 PM
Hello,

I believe this is the expected behavior in this case - the CustomValidator won't fire when the control to validate is empty. To quote MSDN - "If the input control is empty, no validation functions are called and validation succeeds. Use a RequiredFieldValidator control to prevent the user from skipping an input control."

Alternatively set ValidateEmptyText="true"

I hope this helps.

Kind regards,
Tsvetomir Tsonev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
iTools
Top achievements
Rank 1
answered on 05 Aug 2010, 09:49 PM
Hey Tsvetomir,

Very right, I should be using a RequiredFieldValidator for that, my bad :)
The workaround for setting the validationgroup on the controls will be an adequate one for my circumstance.

Thanks,
Jan
Tags
ComboBox
Asked by
iTools
Top achievements
Rank 1
Answers by
iTools
Top achievements
Rank 1
Kalina
Telerik team
T. Tsonev
Telerik team
Share this question
or