inserting data into client script block

S

sklett

Hi-

I understand that the Page class has methods for inserting client script
into the page. I don't want to build my entire client block w/ a
StringBuilder because I only need 1 dynamic variable in the whole block.
So, with that said, here is what I need to do:

<script language="javascript">

var root = <%=m_root%>;
</script>

in my code behind I have a protected string
protected string m_root = "Some value";

I can't find a way to insert or Response.Write() into the client block, it
just renders out my asp script as a string inside the javascript. How do
you do this? I thought it would be easy, but it's escaping me at this time.

Thanks,
Steve
 
M

Michael Ramey

Good, because I was about to tell you that it worked fine for me :) Though
I would be interested in knowing how to do that from a codebehind and not
using <%= %>
 
S

sklett

I'm using an ASP:Literal control. I wanted to use <%=%> but because I'm
using MasterPages, I need to use the literal.

Basically it's like this
asp:Literal id="Literal_Root" runat="server" />

then in the code behind, assuming that you have a MasterPage control named
MasterPage1

((Literal)MasterPage1.FindControl("Literal_Root")).Text = "Some Data";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top