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

[Solved] javascript access to objects and events

2 Answers 37 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
henric
Top achievements
Rank 1
henric asked on 21 Jan 2011, 07:52 AM
Hi there, I am trying to access Telerik MVC objects in MVC project from Javascript (event driven), following the documentation examples:

aspx code:
<%  Html.Telerik().DropDownList()
        .Name("dropdownlist")
        .ClientEvents(events => events
            .OnChange("OnListItemSelected()")
        )
        .BindTo( (SelectList)ViewData["mylist"])                       
        .SelectedIndex(0)                    
        .Render();
%>

and then script:

function OnListItemSelected()
{
    var dropDownList = $("#dropdownlist").data("tDropDownList");
    var selectedValue = dropDownList.value();
 
    ... continue process based on selected value ...
}

problems are:
1. dropDownList variable in the script is ALWAYS null (or undefined) - hence I get exception and cannot access the control values etc...
2. the event OnListItemSelected() is being called at initialization (which might not be necessary but its fine) but it not being triggered thereafter (even if I comment the lines mentioned).

I have removed all other dependencies from the project (scripts like prototype that uses the $ sign) and therefore access to the element via $id should be clear. Still getting the same problem.

Anyone can help?

henric

2 Answers, 1 is accepted

Sort by
0
Accepted
Atanas Korchev
Telerik team
answered on 21 Jan 2011, 08:08 AM
Hello henric,

 Try changing this:
.OnChange("OnListItemSelected()")
with this:

.OnChange("OnListItemSelected")

Regards,
Atanas Korchev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
henric
Top achievements
Rank 1
answered on 21 Jan 2011, 08:20 AM
That seem to be the case!
many thanks.
Tags
General Discussions
Asked by
henric
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
henric
Top achievements
Rank 1
Share this question
or