Slashes dropped from string parameter of javascript method when using ResponseScripts

3 posts, 1 answers
  1. Eddie
    Eddie avatar
    11 posts
    Member since:
    Jun 2007

    Posted 31 Aug 2009 Link to this post


    I want to call a javascript method from the server side using the RadAjaxManager when the user clicks a button.  The javascript method is:

        function RunReport(viewId) { 
            var reportWindow ='DisplayView.aspx?viewId=' + viewId, '_blank', "height=700,width=900,left=20,top=20,scrollbars=auto,status=no,resizable=yes,toolbar=no,menubar=no,location=no"); 

    and the server-side handler for the button is:

            protected void testReport_Click(object sender, EventArgs e) 
                radViewAjaxManager.ResponseScripts.Add(string.Format("RunReport(\"{0}\");", workingView.Id)); 

    The text I'm passing as the viewId has a backslash in it, like "sometext\moretext".  When debugging on the server side, I see that the value of workingView.Id is "sometext\\moretext", so the backslash is being escaped.  However, when I debug the javascript line on the client side as it's being called I see that the viewId is being set to "sometextmoretext", with NO backslash at all in it.

    I also tried wrapping the parameter in the server side in single quotes RunReport('{0}') but that didn't change the behavior.  I feel like I'm overlooking something obvious, but can't quite figure it out.

    Any help would be much appreciated.



  2. Answer
    Veli avatar
    2002 posts

    Posted 01 Sep 2009 Link to this post

    Hello Eddie,

    You need to double-escape your backslashes. Once escaped on the server, the client received "sometext\moretext", thus assuming m is escaped. You need "sometext\\\\moretext" (4 backslashes) :)

    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  3. Telerik UI for ASP.NET Core is out
  4. Eddie
    Eddie avatar
    11 posts
    Member since:
    Jun 2007

    Posted 02 Sep 2009 Link to this post

    That did the trick, thanks so much Veli!
Back to Top