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

AutoPostBack and Validation check by ComboBox

2 Answers 157 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Marco
Top achievements
Rank 2
Marco asked on 30 Jan 2011, 12:52 AM

Hello all,

I do a submit by a ComboBox, AutoPostBack set to True, CausesValidation is set to True and the ValidationGroup is set
In this simple example is only validating the TextBox with a RequiredFieldValidator
And that works, ValidationSummary is showing the message.

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="True" 
    ValidationGroup="item" CausesValidation="True">
    <Items>
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem1" Value="RadComboBoxItem1" />
        <telerik:RadComboBoxItem runat="server" Text="RadComboBoxItem2" Value="RadComboBoxItem2" />
    </Items>
</telerik:RadComboBox>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
    ErrorMessage="RequiredFieldValidator" ValidationGroup="item"></asp:RequiredFieldValidator>
<asp:ValidationSummary ID="ValidationSummary1" runat="server" ValidationGroup="item" />

But the ComboBox is changing to the chosen index while the ValidationGroup is not valid.
How can I prevent the changing of the ComboBox when the ValidationGroup is not valid?
A solution could be to check if the form is valid, and if not then set the ComboBox to its previous value but I don’t know how to check the form and return a True or False, like the method it is done by a PostBack event?

Thanks,

Marco

2 Answers, 1 is accepted

Sort by
0
Marco
Top achievements
Rank 2
answered on 30 Jan 2011, 01:21 AM
I have found a part of the answer.
I can use
Page_ClientValidate("item")
That returns a True or False

The one thing I can't find is how to set the ComboBox to OldValue in Client-side.
In Server Side I can use e.OldValue
0
Marco
Top achievements
Rank 2
answered on 30 Jan 2011, 11:58 AM

To completely answer my own question,

 

<telerik:RadComboBox ID="RadComboBox1" runat="server" AutoPostBack="True" CausesValidation="True"
        OnClientSelectedIndexChanging="validatePage">
<script language="javascript" type="text/javascript">
    function validatePage(sender, args) {
        if (!Page_ClientValidate("item"))
            args.set_cancel(true);
    }
</script>

Tags
ComboBox
Asked by
Marco
Top achievements
Rank 2
Answers by
Marco
Top achievements
Rank 2
Share this question
or