clickclickbang
asked on
Printing Client Script Value
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> </p>";
Any ideas?
Thanks for the tips!
~ C
protected override void Render(HtmlTextWriter writer)
{
writer.write("var MyVar = '" + this.ClientScriptValue + "';");
}
Results in :
var MyVar = "<p>asdf</p>
<p> </p>";
Any ideas?
Thanks for the tips!
~ C
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
--Nauman.
ASKER
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!
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!
ASKER
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?