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

Slashes dropped from string parameter of javascript method when using ResponseScripts

2 Answers 1409 Views
Ajax
This is a migrated thread and some comments may be shown as answers.
Eddie
Top achievements
Rank 2
Eddie asked on 31 Aug 2009, 05:06 PM
Hello,

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 = window.open('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.

Thanks!

Eddie

2 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 01 Sep 2009, 08:15 AM
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) :)

Greetings,
Veli
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.
0
Eddie
Top achievements
Rank 2
answered on 02 Sep 2009, 06:13 PM
That did the trick, thanks so much Veli!
Tags
Ajax
Asked by
Eddie
Top achievements
Rank 2
Answers by
Veli
Telerik team
Eddie
Top achievements
Rank 2
Share this question
or