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

Create Client Event Property to UserControl ComboBox

6 Answers 155 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Mahmoud
Top achievements
Rank 1
Mahmoud asked on 08 Feb 2012, 08:58 AM
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

6 Answers, 1 is accepted

Sort by
0
Accepted
RvdGrint
Top achievements
Rank 1
answered on 08 Feb 2012, 12:06 PM
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

0
Mahmoud
Top achievements
Rank 1
answered on 08 Feb 2012, 05:09 PM
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



0
RvdGrint
Top achievements
Rank 1
answered on 09 Feb 2012, 07:58 AM
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
0
Mahmoud
Top achievements
Rank 1
answered on 09 Feb 2012, 08:11 AM
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
0
RvdGrint
Top achievements
Rank 1
answered on 09 Feb 2012, 08:23 AM
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
0
Mahmoud
Top achievements
Rank 1
answered on 09 Feb 2012, 08:52 AM
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
Tags
ComboBox
Asked by
Mahmoud
Top achievements
Rank 1
Answers by
RvdGrint
Top achievements
Rank 1
Mahmoud
Top achievements
Rank 1
Share this question
or