Home All Groups Group Topic Archive Search About

How to show variable on webpage?

Author
14 Jan 2006 6:45 AM
brett
I'd like to display a string variable on a webpage depending if the URL
has "localhost" in it or not.  The string variable will have line
breaks and this text:
<script type="text/javascript" language="javascript">

How do I go about accomplishing this?

Thanks,
Brett

Author
14 Jan 2006 3:17 PM
Peter Bromberg [C# MVP]
Using a placeholder on the page, and a LiteralControl to hold your "text":

if(Request.Url.IndexOf("localhost") !=-1)
{

myPlaceHolder.Controls.Add(new LiteralControl("yourtexthere"));

}

--Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quote
"brett" wrote:

> I'd like to display a string variable on a webpage depending if the URL
> has "localhost" in it or not.  The string variable will have line
> breaks and this text:
> <script type="text/javascript" language="javascript">
>
> How do I go about accomplishing this?
>
> Thanks,
> Brett
>
>
Author
14 Jan 2006 11:34 PM
brett
That doesn't allow me to put a string such as

<!-- Start of StatCounter Code -->
            var sc_project=116000;
            var sc_invisible=1;

Why doesn't the c# @ for literals work in ASP.NET?

Thanks,
Brett
Author
14 Jan 2006 11:55 PM
Peter Bromberg [C# MVP]
You have to be specific about what you really want to do. It looks now like
what you are saying is "I want to embed some client side script in my page".

For that, you can use the Page.RegisterClientScriptBlock method:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWebUIPageClassRegisterClientScriptBlockTopic.asp

Cheers.
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com




Show quote
"brett" wrote:

> That doesn't allow me to put a string such as
>
> <!-- Start of StatCounter Code -->
>             var sc_project=116000;
>             var sc_invisible=1;
>
> Why doesn't the c# @ for literals work in ASP.NET?
>
> Thanks,
> Brett
>
>
Author
15 Jan 2006 1:08 AM
brett
Yes - that is what I want to do.  I have the code running fine but I
never see the javascript in the webpage.  I'm using code behind rather
than c# script tags.  Does that make a difference?  I'm doing
everything on Page_Load() in the CS file.

Thanks,
Brett
Author
16 Jan 2006 6:15 AM
Patrick.O.Ige
It doesn't make any difference.
If you have any more questions just post it
Patrick

Show quote
"brett" <acco***@cygen.com> wrote in message
news:1137287318.036393.117360@g47g2000cwa.googlegroups.com...
> Yes - that is what I want to do.  I have the code running fine but I
> never see the javascript in the webpage.  I'm using code behind rather
> than c# script tags.  Does that make a difference?  I'm doing
> everything on Page_Load() in the CS file.
>
> Thanks,
> Brett
>

AddThis Social Bookmark Button