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

[Solved] Drop down event

1 Answer 152 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
chithuraj
Top achievements
Rank 1
chithuraj asked on 20 Sep 2009, 08:39 AM
Hi,
        I have Rad Dropdown. I am validating the Dropdown on Server side selected index change event, my problem is i am using custom validation. When the select dropdown and directly click next button, Then it needs two times to go on next page, Is there is any client events After firing serverside Index change event. in that client side event i have to make, args.isvalid=true.

Here is my sample code.
 
protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e) 
    { 
        try 
        { 
            hdnReturnBackCatId1.Value = "0"
            RadComboBox1.SelectedItem.Text = RadTreeView1.SelectedNode.Text; 
            RadComboBox1.SelectedItem.Value = RadTreeView1.SelectedNode.Value; 
            bool blnRetVal = ValidatingForParentCategory(lblCat1, RadComboBox1); 
            if (blnRetVal == true) 
            { 
                lblCat1.Visible = false
 
                hdnParentCategoryId.Value = "1"
                RadComboBox1.SelectedIndex = 0
                CustomValCategory1.ErrorMessage = "Please associate to child category"
            } 
            else 
            { 
                
                lblCat1.Visible = false
                hdnParentCategoryId.Value = "0"
               // RadComboBox1.OnClientDropDownClosed = "CloseRadCombo1"
               // CustomValCategory1.ClientValidationFunction = " false"
               // CustomValCategory1.ControlToValidate = " RadComboBox1"
              //  CustomValCategory1.ServerValidate += new ServerValidateEventHandler(this.ServerValidation); 
 
            } 
        } 
        catch (Exception ex) 
        { 
            Master.LogError("AddNewproductsStep2.cs", "RadComboBox1_SelectedIndexChanged()", ex.Message + ":" + ex.StackTrace + ":" + ex.StackTrace); 
        } 
    } 
clientside 
 
<asp:UpdatePanel ID="UpdCat1" runat="server"
                                                                    <ContentTemplate> 
                                                                        <asp:HiddenField ID="hdnParentCategoryId" runat="server" Value="1" /> 
                                                                        <telerik:RadComboBox OnClientDropDownClosing="CloseRadCombo1"   ID="RadComboBox1" Width="300px" runat="server" OnClientDropDownOpened="OnClientDropDownOpenedHandlerForCategory1" 
                                                                             Style="vertical-align: middle;" AutoPostBack="true" ValidationGroup="Category1Group" 
                                                                            Skin="Office2007" OnInit="RadComboBox1_Init" CausesValidation="false" OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged"
                                                                            <ItemTemplate> 
                                                                                <div id="div1"
                                                                                    <telerik:RadTreeView ID="RadTreeView1" Skin="Office2007" runat="server" OnClientNodeClicking="nodeClickingForCategory1"
                                                                                    </telerik:RadTreeView> 
                                                                                </div> 
                                                                            </ItemTemplate> 
                                                                            <Items> 
                                                                                <telerik:RadComboBoxItem Text="" Value="" /> 
                                                                            </Items> 
                                                                        </telerik:RadComboBox> 
                                                                        <asp:UpdateProgress ID="UpdateProgressCategory1" runat="server" AssociatedUpdatePanelID="UpdCat1" 
                                                                            DisplayAfter="100" DynamicLayout="true"
                                                                            <ProgressTemplate> 
                                                                                <img alt="Progress" border="0" src="Images/progress.gif" /> 
                                                                                <span>Validating ...</span> 
                                                                            </ProgressTemplate> 
                                                                        </asp:UpdateProgress> 
                                                                        <asp:CustomValidator ID="CustomValCategory1" ValidationGroup="Category1Group" runat="server" 
                                                                            ErrorMessage=""  ClientValidationFunction="validateCombo" Display="Dynamic"  ></asp:CustomValidator> 
                                                                        <asp:Label ID="lblCustomErrorMessage" runat="server" ForeColor="Red" Text=""></asp:Label> 
                                                                        <%--     &nbsp;<asp:RequiredFieldValidator ID="ReqCategory1" ControlToValidate="RadComboBox1" 
                                                                            runat="server" InitialValue="0" ErrorMessage="select"></asp:RequiredFieldValidator> 
                                                                        <br />--%> 
                                                                        <asp:Label ID="lblCat1" runat="server" Visible="false" ForeColor="Red" Text="Please associate to child category"></asp:Label> 
                                                                    </ContentTemplate> 
                                                                    <Triggers> 
                                                                        <asp:AsyncPostBackTrigger ControlID="RadComboBox1" EventName="SelectedIndexChanged" /> 
                                                                    </Triggers> 
                                                                </asp:UpdatePanel> 
 
 
 
The custom javascript is, 
 
 
 function validateCombo(source, args) 
  { 
        var combo = $find("<%=RadComboBox1.ClientID%>");      
        items = combo.get_items();   
        if(combo.get_text()=="Category") 
        { 
            document.getElementById("<%=lblCustomErrorMessage.ClientID %>").innerHTML="You must select a category"
            document.getElementById("<%=CustomValCategory1.ClientID %>") .innerHTML=''
         }     
             
        //if(combo.get_text() == items.getItem(0).get_text())     
        if(document.getElementById("<%=hdnParentCategoryId.ClientID %>").value == 1)     
        {     
            args.IsValid = false;     
        }     
        else    
        {     
            args.IsValid = true;     
        }    
  } 



Please Help me..
Any help will be Appreciated!!

Thanks and Regards!
chithuraj.j

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 21 Sep 2009, 02:41 PM
Hi Chithuraj,

I am not sure if there is any client event which fires after the server side SelectionIndexChanged event of the RadComboBox. But a suggestion would be to use RegisterStartupScript method to call a clientside function from the code behind.

Hope this makes sense.. :)
Princy.
Tags
ComboBox
Asked by
chithuraj
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or