String Builder

S

shapper

Hello,

I am creating a string using StringBuilder:

Dim code As New StringBuilder
code.Append("<script type=""text/javascript""><!--")
Response.Write(code.ToString)

However, I don't get any code when I do Response.Write.

I thinks it is because of "".

Could someone, please, help me out with this?

Thanks,

Miguel
 
K

Karch

the quick answer is that you don't need double quotes for javascript - try
this:

Dim code As New StringBuilder
code.Append("<script type='text/javascript'><!--")
Response.Write(code.ToString)
 
T

TiSch

Hello,

I am creating a string using StringBuilder:

Dim code As New StringBuilder
code.Append("<script type=""text/javascript""><!--")
Response.Write(code.ToString)

However, I don't get any code when I do Response.Write.

I thinks it is because of "".

Could someone, please, help me out with this?

Thanks,

Miguel

Hello,
why do you want to write the script.tag to the page? The double quotes
are not hte problem because you have masked them correctly.
The String IS written to the page but because its a javascript , its
not visible direclty. Look at the html-sourcecode and you will see it
at the top of the page.
A better way to register scripts on a page is the function
Page.RegisterClientScriptBlock to register a script which is executed
directly. Use this function for script-functions you want to calllater.
You cant access page-controls at this time because they are still
loading.
If you want to access page-controls use the .net-function
Page.RegisterStartupScript which will be executed when the page is
loaded.

Regards,
Tim
 
S

shapper

Hi,

I know about RegisterClientScriptBlock. The problem is that I am
creating a control thats ads a Google AdSense ad to the page.

So, if I am not wrong, I need to add the code exactly to the place on
my page where I want the add to be.

For this reason by custom control includes a literal where text is
equal to Google AdSense code which can be as follows:

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "image";
google_ad_channel = "";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Anyway, is this the right way to do this?

Any sugestion will be welcome.

Thanks,
Miguel
 
T

TiSch

Hi,

I know about RegisterClientScriptBlock. The problem is that I am
creating a control thats ads a Google AdSense ad to the page.

So, if I am not wrong, I need to add the code exactly to the place on
my page where I want the add to be.

For this reason by custom control includes a literal where text is
equal to Google AdSense code which can be as follows:

<script type="text/javascript"><!--
google_ad_client = "pub-xxxxxxxxxxxxxxxx";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "image";
google_ad_channel = "";
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Anyway, is this the right way to do this?

Any sugestion will be welcome.

Thanks,
Miguel

Hi,
im not familiar with google adsense but you can add the script where
ever you want for exaple:

Dim script As String = vbCrLf & _
"<script type=""text/javascript""
language=""JavaScript""
src=""http://pagead2.googlesyndication.com/pagead/show_ads.js>" &
vbCrLf & _
" google_ad_client = ""pub-xxxxxxxxxxxxxxxx"";" &
vbCrLf & _
" google_ad_width = 728;" & vbCrLf & _
" google_ad_height = 90;" & vbCrLf & _
" google_ad_format = ""728x90_as"";" & vbCrLf & _
" google_ad_type = ""image"";" & vbCrLf & _
" google_ad_channel = """";" & vbCrLf & _
"</script>"

Me.PlaceHolder1.Controls.Add(New LiteralControl(script))

Ragards,
Tim
 

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

Forum statistics

Threads
473,779
Messages
2,569,606
Members
45,239
Latest member
Alex Young

Latest Threads

Top