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

[Solved] Telerik grid client template not working as expected if any of the parameter value contains Apostrophe (')

1 Answer 77 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.
Lalit
Top achievements
Rank 1
Lalit asked on 08 Aug 2012, 09:08 PM
Hi

I have implemented a client template in my telerik grid as below .
ClientTemplate("<a href='javascript:viewUser(\"<#= Column1 #>\", \"<#= Column2 #>\", \"<#= Column3 #>\",\"<#= removeSpecialCharacter(FirstName) #>\",\"<#= Column4 #>\")'><#= Column5#>...</a>")

When ever there is apostrophe in FirstName value, the html is not getting generated properly in client. it is like -
<a href="javascript:viewUser("Test1", "Test3", "test4","\" ?,?test5?)?="">Display</a>

if there is no  apostrophe in FirstName value, the html is getting genarated perfectly fine like -
<a href="javascript:viewUser("test1", "test2", "test3","test4","test5")">Display</a>

In client template, I have also implement a function removeSpecialCharacter to escape special character  ' but still having the problem.The function is as follow :-

function removeSpecialCharacter(inputString){
  
    return inputString.replace("'", "\\'");
  
 
  
}

Could you pls look into this and let me know the issue? Thanks a lot in advance...








1 Answer, 1 is accepted

Sort by
0
Petur Subev
Telerik team
answered on 10 Aug 2012, 09:26 AM
Hello Lalit,

Usually in such scenarios it is more convenient to use an exarnal JavaScript function which could handle the formatting.
e.g.
ClientTemplate("<a href='<#= getUrl(data) #>'><#= Column5#>...</a>")
 
<script>
      function getUrl(dataItem){
            // here you can access each of the fields - dataItem.Column1 etc. and finally return the concatenated string
      }
</script>

Also you might try to change the outer href apostrophes to quotes .
i.e.
.ClientTemplate("<a href=\" <#= test(data) #> \"></a>");



Regards,
Petur Subev
the Telerik team
Check out the successor of Telerik MVC Extensions - Kendo UI for ASP.NET MVC - and deem it for new ASP.NET MVC development.
Tags
General Discussions
Asked by
Lalit
Top achievements
Rank 1
Answers by
Petur Subev
Telerik team
Share this question
or