Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > Telerik grid client template not working as expected if any of the parameter value contains Apostrophe (')

Not answered Telerik grid client template not working as expected if any of the parameter value contains Apostrophe (')

Feed from this thread
  • Lalit avatar

    Posted on Aug 8, 2012 (permalink)

    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...








    Reply

  • Petur Subev Petur Subev admin's avatar

    Posted on Aug 10, 2012 (permalink)

    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.

    Reply

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / Telerik MVC Extensions (superseded) > General Discussions > Telerik grid client template not working as expected if any of the parameter value contains Apostrophe (')