0
votes

I'm trying to call a function with arguments from Telerik grid ClientTemplate, like this:

.ClientTemplate("<a href=\"javascript:OnModifyDescription('<#= Value1 #>');\" title='Modify'>...</a>")

When the Value argument contains a single quote then on clicking the link results in the error: "Uncaught SyntaxError: Unexpected identifier".

What is the correct way to bind a function in a ClientTemplate?

Thanks in advance.

1
Why is everything on one line? And for the love of ... well, everyone, don't ever use href="javascript:..." links! - Tomalak
Thanks for reply. The code is wrapped now. Could you please advise me the correct syntax then? - Alexander
This is not about syntax. Your entire approach is wrong, correcting the syntax will not lead you anywhere. Unfortunately I don't know enough about Telerik MVC to guide you. I've re-phrased your question a bit, though. Maybe someone else sees it. - Tomalak

1 Answers

1
votes

Make your client template as this :

.ClientTemplate("<a class='MyClass' myAttrib='<#= Value1 #>') title='Modify'>...</a>")

Then write the following scripts at top of your page:

<script>
$('a.MyClass').live('click',function(){
   var myVal = $(this).attr('myAttrib');
   OnModifyDescription(myVal);
});
</script>

Check this for jquery live function : http://api.jquery.com/live/