Problem getting and setting the selected value of the rad combo box in the javascript when adding the javascript through code behind.

8 posts, 0 answers
  1. Mausami
    Mausami avatar
    10 posts
    Member since:
    Jan 2009

    Posted 20 Jan 2009 Link to this post

    Hello,

    I have a rad combo box , a rad date picker and a required field validator for the rad date picker in a rad grid.

    I have added through code behind, a javascript for the rad combo box's client side event 'OnClientSelectedIndexChanged'.

    I need the selected value of the rad combo box in the javascript to enable or disable the required field validator present in the corresponding row.

    I pass the rad combo box's ClientID and required field validator's ClientID as parameters thru backend to this function.

    In order to get the selected value, I have tried using the following piece of code,

       <script type="text/javascript">
     
           function OnClientSelectedIndexChanged(radComboClientID, reqFieldValidatorClientID)
          {
              //getting the selected value
              alert(radComboClientID.GetValue());
           }

        </script>

    It doesn't work; giving an error 'Object doesn't support this property or method'

    Is there any way to access the selected value in this javascript.

    Kindly help solving this issue.

    Thanks,
    Mausami.

  2. Serrin
    Serrin avatar
    286 posts
    Member since:
    Sep 2008

    Posted 20 Jan 2009 Link to this post

    Heya Mausami,

    You could try something along these lines:

    aspx javascript:
    function HandleEndChanging(sender, args)  
                {      
                    var item = args.get_item();  
                    alert(sender.get_text());  
                } 

    And in the control definition...
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Height="170px" Width="204px" 
                        Skin="Default" ShowMoreResultsBox="True"                        
                        EnableLoadOnDemand="True"   
                        OnClientSelectedIndexChanged="HandleEndChanging"   
    </telerik:RadComboBox> 

    This should work just fine, and this code was pilfered from the RadComboBox client-side demo and modified slightly. :)

     

    This should get you started on getting the value of the text in RadCombo, then you would just use that for whatever operation you are going for.

     

    -Serrin

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mausami
    Mausami avatar
    10 posts
    Member since:
    Jan 2009

    Posted 20 Jan 2009 Link to this post

    Hi Serrin,

    Thanks for the reply.

    Using the above javascript I get the error --  'undefined' is null or not an object.

    I am able to get the selected text by calling the javascript in the aspx page as given below.

    <rad:RadComboBox ID="radComboStatus" runat="server" Skin="WindowsXP" AutoPostBack="false" DataTextField="EmployeeStatusDescription" DataValueField="EmployeeStatusCode" Width="100px" OnClientSelectedIndexChanged="HandleEndChanging"></rad:RadComboBox>

    To get the value :
        <script type="text/javascript">
            function HandleEndChanging(item)  
            {      
                alert(item.ComboBox.GetValue());  
            }
       </script>

    To get the text :

        <script type="text/javascript">
            function HandleEndChanging(item)  
            {      
                alert(item.ComboBox.GetText());  
            }
       </script>

    But my requirement is different .

     I need the ClientID  of the required field validator also which is present in the corresponding grid row as that of the RadComboBox.
    So adding the javascript function in the aspx file as in the above example will not help me.

    I want to add the javascript function through code behind in the 'ItemDataBound'  event of the grid as given below.

        protected void radGridEmployeesDetails_ItemDataBound(object sender, GridItemEventArgs e)
        {
             if (e.Item is GridDataItem)
                { 
                     RadComboBox radCmbStatus = (RadComboBox)e.Item.FindControl("radComboStatus");
                     RequiredFieldValidator reqField = (RequiredFieldValidator)e.Item.FindControl("EffectiveDateValidator");

                     if(radCmbStatus != null && reqField!= null)
                     {
                           string functionName = String.Format("OnClientSelectedIndexChanged('{0}', '{1}')", radCmbStatus.ClientID, reqField.ClientID); 
                           radCmbStatus.OnClientSelectedIndexChanged = functionName;                                       
                  
                     }
             }
       }

    Hope you got my requirement !
    Is there any way of getting the selected value in the javascript function using the ClientID of the radComboBox passed as a parameter.


    Thanks,
    Mausami

  5. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 21 Jan 2009 Link to this post

    Hi Mausami,

    The code of Serrin is related to RadCombobox for ASP.NET AJAX.
    You are using the "classic" RadComboBox maybe?

    Please shed some light on the exact version.

    Sincerely yours,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  6. Mausami
    Mausami avatar
    10 posts
    Member since:
    Jan 2009

    Posted 21 Jan 2009 Link to this post

    Hi Veselin,

    The Product version and Assembly version of the RadCombobox which I am using is 2.8.5.0.

    Thanks,
    Mausami
  7. Mausami
    Mausami avatar
    10 posts
    Member since:
    Jan 2009

    Posted 23 Jan 2009 Link to this post

    Hi Veselin, Serrin,

    Just wanted to know whether my requirement can be fulfilled using the version of ddl that I have.

    Thanks.
    Mausami
  8. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 26 Jan 2009 Link to this post

    Hi Mausami,

    The OnClientSelectedIndexChanged event handler should accept only one parameter - the newly selected  item.

    I assume that you want to access the requred field validator client object when the item is changed.
    Here is how you can do it:

    <EditFormSettings EditFormType="Template"
        <FormTemplate> 
            <rad:RadComboBox id="RadComboBox1" runat="server"  
                AllowCustomText="True" DataSourceID="AccessDataSource1" 
                SelectedValue='<%# Bind("Name") %>'  
                DataTextField="Name" 
                DataValueField="Name" 
                OnClientSelectedIndexChanged="OnClientSelectedIndexChangedHandler" 
                Width="150px"
            </rad:RadComboBox> 
            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"  
                ErrorMessage="RequiredFieldValidator"  
                ControlToValidate="RadComboBox1"
             </asp:RequiredFieldValidator> 
            <asp:Button ID="btn1" runat="server" Text="Save" />                             
        </FormTemplate> 
    </EditFormSettings> 

    <script type="text/javascript"
    function OnClientSelectedIndexChangedHandler(item) 
        var combo = item.ComboBox; 
        var validatorID = combo.ClientID.replace("RadComboBox1""RequiredFieldValidator1"); 
        //find the validator 
        var validator = document.getElementById(validatorID); 
    </script>  

    I hope this helps.

    Kind regards,
    Veselin Vasilev
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
  9. Mausami
    Mausami avatar
    10 posts
    Member since:
    Jan 2009

    Posted 27 Jan 2009 Link to this post

    Hi Veselin,

    The above piece of code given by you has helped me implementing my requirement  :)
    Many thanks !!

    Regards,
    Mausami

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017