Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ComboBox > Create Client Event Property to UserControl ComboBox

Answered Create Client Event Property to UserControl ComboBox

Feed from this thread
  • Mahmoud avatar

    Posted on Feb 8, 2012 (permalink)

    Hi,

    I have a RadComboBox as a UserControl ,

    I Created Some Custom Properties to it from CodeBehind ,
    I Succedded adding a Server Event which is  OnSelectedIndexChanged .

    The Question is:

    How to add a Client Event On it.

     --> Specifically I want to add OnClientSelectedIndexChanged Event

    Please Can anyone tell me how to do that

    I believe it is a JavaScript Code or Something like that

    I need Help Quickly Please...

    Best Regards,

    Mahmoud

    Reply

  • Posted on Feb 8, 2012 (permalink)

    Mahmoud,

    there are several options. You can add all of the code (including javascript) from code-behind like this:
    string sJavaJobTitle = "function (sender, eventArgs) {{ "
                          + "var _desc = sender.get_selectedItem().get_attributes().getAttribute('Description'); "
                          + String.Format("var _tbDesc = $find('{0}'); ", rtbJobDescription.ClientID)
                          + "if (_tbDesc) {{ if (_tbDesc.get_value() == '') {{ _tbDesc.set_value(_desc); }} }} "
                          + "}}";
    rcbJobTitle.OnClientSelectedIndexChanged = sJavaJobTitle;

    Or define a javascript function in the aspx/ascx/js and assign the function name to the OnClientSelectedIndexChanged like this:
    function ComboIndexChanged(sender, args) {
    /*Do something*/
    }
    rcbCombo.OnClientSelectedIndexChanged = "ComboIndexChanged";

    Regards,
     Jos

    Reply

  • Mahmoud avatar

    Posted on Feb 8, 2012 (permalink)

    Hi JosM,

    it gives me an error ( Error: 'ComboIndexChanged' is undefined )  ..

    also, The intellisense doesn't show the property between combobox tags .

    Please See How I managed to add the OnSelectedIndexChanged server event .
    and maybe you can give me the code for OnClientSelectedIndexChanged

    UserControl Code Behind :
    Public Event SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs)
     
    Protected Overridable Sub OnSelectedIndexChanged(ByVal e As System.EventArgs)
      RaiseEvent SelectedIndexChanged(Me, e)
    End Sub
     
    Protected Sub RadComboBoxDescription_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles RadComboBoxDescription.SelectedIndexChanged
      OnSelectedIndexChanged(e)
    End Sub



    Reply

  • Posted on Feb 9, 2012 (permalink)

    Mahmoud,

    the client-side code (OnClientSelectedIndexChanged) has nothing to do with the serverside.
    I already gave you the solution for OnClientSelectedIndexChanged.

    - Which of the 2 option have you tried?
    - If option 2: Where have you defined you're javascrip function?

    Regards,
      Jos

    Reply

  • Mahmoud avatar

    Posted on Feb 9, 2012 (permalink)

    Hi JosM,

    what you gave me is a Static Solution ( static Javascript code in usercontrol page ) .

    I want a Dynamic Solution where I can put my javascript code in my own page and 
    use the event on many pages.

    Can you briefly explain please..

    Greetings,
    Mahmoud

    Reply

  • Posted on Feb 9, 2012 (permalink)

    Mahmoud,

    My second option was to define a javascript function and put on the *.ascx (UserControl), *.aspx (Page) or *.js (javascript which can be loaded on the page). You can call this function from the User Control like I told you in my second option.

    My first option is far of static. You can modifiy this so you can generate the function youw want. But the function has to be assigned to the control, that indeed is static.

    Regards,
      Jos

    Reply

  • Mahmoud avatar

    Posted on Feb 9, 2012 (permalink)

    Hi JosM,

    I put The Second Solution you mentioned in aspx Page and it worked Fine
    just as you would expect

    Thank you very much.

    Best Regards,
    Mahmoud

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET AJAX > ComboBox > Create Client Event Property to UserControl ComboBox
Related resources for "Create Client Event Property to UserControl ComboBox"

ASP.NET ComboBox Features  |  Documentation  |  Demos  |  Telerik TV  |  Self-Paced Trainer  |  Step-by-step Tutorial  ]