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

[Solved] onclick doesn't work in template for a bound column

2 Answers 65 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Young
Top achievements
Rank 1
Young asked on 23 Aug 2012, 03:38 PM

Hi,

I have a Telerik grid data bound column which has a template.

The problem I am having is when I click the image button generated in the column, I get a JavaScript error saying 'missing ) after argument list'

The thing is, if the description passed through is a number (e.g. 12) then the JavaScript method runs successfully, however, if description is a string (e.g. test) then it throws this error.

Please can someone offer me some advice on how I can fix this and where I am going wrong as I am struggling to find the solution.

The following is my code - client template part works perfect, it's just the template part that the above problem is happening in.

Thank you very much.

columns.Bound(o => o.Id)

.Template(@<text> <ul class="class1">

                  <li class="class2"><a href="#" onclick="myMethod(@item.Id, @item.Description);"></a></li>

                  </ul>

          </text>)

.ClientTemplate("<ul class='class1'>" +

                "<li class='class2'><a href='#' onclick='myMethod(<#=Id#>, \"<#=Description#>\")' ></a></li> " + "</ul>")


2 Answers, 1 is accepted

Sort by
0
Accepted
AspenSquare
Top achievements
Rank 1
answered on 23 Aug 2012, 03:55 PM
Did you try enclosing them in quotes?


<li class="class2"><a href="#" onclick="myMethod('@item.Id', '@item.Description');"></a></li>


0
Young
Top achievements
Rank 1
answered on 23 Aug 2012, 04:42 PM
Thank you, it works now i enclosed them in ' '.
Much appreciated. 
Tags
Grid
Asked by
Young
Top achievements
Rank 1
Answers by
AspenSquare
Top achievements
Rank 1
Young
Top achievements
Rank 1
Share this question
or