Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printing Client Script Value

Posted on 2006-10-30
4
Medium Priority
?
256 Views
Last Modified: 2010-08-05
Experts, I need to print a client script value from a web control, but when printing the value the string seems to wrap to a new line thus triggering a JavaScript unterminated string constant error.

        protected override void Render(HtmlTextWriter writer)
        {
            writer.write("var MyVar = '" + this.ClientScriptValue + "';");
        }

Results in :

var MyVar = "<p>asdf</p>
<p>&nbsp;</p>";

Any ideas?

Thanks for the tips!

~ C
0
Comment
Question by:clickclickbang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 25

Accepted Solution

by:
nauman_ahmed earned 2000 total points
ID: 17835191
Any specific reason for using HtmlTextWriter? An easier way would be to declare a literal control in ASPX
set its value to JS from code-behind

<asp:Literal id="lblJs" runat="server" />

from code-behind:

string strScript = "";
strScript = "<script langugage=\"javsacript\">var MyVar='"+this.ClientScriptValue+"';</script>"
lblJs.Value = strScript;

--Nauman.
0
 
LVL 1

Author Comment

by:clickclickbang
ID: 17835285
Nauman, this is actually a a web control not an aspx page.

public class MyCustomWebControl : WebControl
{

}

I could use a composite Literal inside the control, but wouldn't it present the same line wrapping issue as before?
0
 
LVL 25

Expert Comment

by:nauman_ahmed
ID: 17835445
HtmlTextWriter causes the above output since it behaves differently when you try to write something to the output. Try using composite Literal control and see if it solves the issue.

--Nauman.
0
 
LVL 1

Author Comment

by:clickclickbang
ID: 17835956
I ran into the same problem with the Literal control. It seems to add line breaks in the string. The string source is a txt file.

Here is a sample from the txt file:

<p>This is a test</p>
<p>Hey how are you?</p>

If I manually remove the line break:

<p>This is a test</p><p>Hey how are you?</p>

It works okay. Is there a way to do this programatically?

Thanks for your help!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question