Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > How to Trigger Javascript on Blur or Item Changed
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Not answered How to Trigger Javascript on Blur or Item Changed

Feed from this thread
  • Brock avatar

    Posted on May 10, 2011 (permalink)

    In my vb.net code, I'm getting client ID's and passing them to a Javascript function already defined on my asp page. I have a radcombobox in a radgrid. When you select an item in the radcombobox, I would like my javascript function to be executed. I don't care if this happens when the selected item is changed or when the radcombo loses focus. Any help would be greatly appreciated.
    Here's what I have so far.

    radcombobox.Attributes.Add("OnClientBlur", "return jsFunction('" + radcombobox.ClientID  + "');")

    This doesn't work.

    The majority of the examples I've found online are in C#... but I'm trying to do this in vb.net.

  • Posted on May 11, 2011 (permalink)

    Hello Brock,

    When a RadControl client event taken place, it pass two default paramenters, sender(here the combobox) and arguments. I suppose you are trying to pass the same combobox (radcombobox) ID to the function.If so no need not to pass the client ID explicitly as you did. You can atatch the event for aspx itself.
    aspx:
    <EditItemTemplate>                                                
      <telerik:RadComboBox ID="RadCombo" runat="server"  AllowCustomText="true" OnClientBlur="OnClientBlur">
         <Items>
          <telerik:RadComboBoxItem Value="1" Text="Item1" />
          <telerik:RadComboBoxItem Value="2" Text="Item2" />
         <telerik:RadComboBoxItem Value="3" Text="Item3" />
        </Items>
     </telerik:RadComboBox>
    </EditItemTemplate>

    Javascript:
    function OnClientBlur(sender, args)
       {
            var combo = sender;//here  sender is the combobox
        }

    If you want to pass extra parameters you cannot pass the extra arguments directly.The easiest way to pass predefined parameters to a function executed on the clientside, is to assign anonymous function and pass the parameters:
    Here is a sample code:
    VB:
    Protected Sub RadGrid1_ItemCreated(sender As Object, e As GridItemEventArgs)
        If TypeOf e.Item Is GridEditFormItem AndAlso e.Item.IsInEditMode Then
            Dim item As GridEditFormItem = DirectCast(e.Item, GridEditFormItem)
            Dim combo As RadComboBox = DirectCast(item.FindControl("RadCombo"), RadComboBox)
            combo.OnClientSelectedIndexChanged = "function (button,args){OnClientSelectedIndexChanged ('" + editItem.ItemIndex & "');}"
        End If
    End Sub

    Javascript:
    function OnClientSelectedIndexChanged (rowIndex)
        {
            alert(rowIndex);
        }

    Hope it helps.
    Princy.

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Combobox > How to Trigger Javascript on Blur or Item Changed