AddHeader is not working

R

Rick

I am trying to add a new header to the HTML when a webform loads. But it
does not seem to work.
I need to get this working in a Sharepoint webpart so adding it to the HTML
page is not an option.

Can anyone tell me of another way or what I'm doing wrong?
I've tried the following in the Page Load Event.

Response.AppendHeader("Test", "Test")
Response.AddHeader("Test", "Test")
context.response.addheader("test","test")
context.response.appendheader("test","test")
Thanks in advance,
Rick
 
J

Joerg Jooss

Rick said:
I am trying to add a new header to the HTML when a webform loads. But
it does not seem to work. I need to get this working in a Sharepoint
webpart so adding it to the HTML page is not an option.

Can anyone tell me of another way or what I'm doing wrong?
I've tried the following in the Page Load Event.

Response.AppendHeader("Test", "Test")
Response.AddHeader("Test", "Test")
context.response.addheader("test","test")
context.response.appendheader("test","test")

You're confusing HTML with HTTP. You cannot use HTTP headers as HTML
elements.

Cheers,
 
R

Rick

Ok, Thanks!

But do you know how I can add, programatically, the following line in the
HTML code:
<meta http-equiv="refresh" content="600"> ?
 
K

Kevin Spencer

That would have to go into the <head> section of the document. Another
option would be to add a JavaScript. Example:

<script type=text/javascript><!--
function refresh()
{
var s = document.location.href;
window.location = s;
}
setTimeout(refresh, 1000);
--></script>

Note that the time is in milliseconds.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.

Rick said:
Ok, Thanks!

But do you know how I can add, programatically, the following line in the
HTML code:
<meta http-equiv="refresh" content="600"> ?
 
R

Rick

I realize that it needs to be in the <head> section, my problem is, I'm not
sure How to get it there from the page load event of VS.net. I have to put
this into a webpart, which I am not sure how to get to the HTML through
webpart code(VB.NET). One problem I have with the Java script, is it would
need to be added as an "onload" to the <body> tag, which does not have an
ID, If I had an ID I could easily add it to the Body tag like this:
myBody.Attributes.Add("onload", "javascript:
setInterval('location.reload();', 4000)")

Kevin Spencer said:
That would have to go into the <head> section of the document. Another
option would be to add a JavaScript. Example:

<script type=text/javascript><!--
function refresh()
{
var s = document.location.href;
window.location = s;
}
setTimeout(refresh, 1000);
--></script>

Note that the time is in milliseconds.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.
 
K

Kevin Spencer

You won't be able to add anything to the <head> tag in a WebPart. That's why
I posted the alternative. Also, it's not necessary to put it into the onload
of the body tag. Any JavaScript that isn't in a function block is executed
immediately. So, if you want to use your version, just put a script with
your code in it anywhere in the page. that would include inside a WebPart.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Ambiguity has a certain quality to it.
 
R

Rick

I figured it out: I didn't realize you could just register a javascript and
it would run without user action. Anyway this is how it was done:

Dim sScript As String

sScript = "<script language='javascript'>"
sScript += "setInterval('location.reload();', 4000);"
sScript += "</script>"

If Not Page.IsClientScriptBlockRegistered("refreshscript") Then
Page.RegisterClientScriptBlock("refreshscript", sScript)
End If

Kevin Spencer said:
That would have to go into the <head> section of the document. Another
option would be to add a JavaScript. Example:

<script type=text/javascript><!--
function refresh()
{
var s = document.location.href;
window.location = s;
}
setTimeout(refresh, 1000);
--></script>

Note that the time is in milliseconds.

--
HTH,

Kevin Spencer
Microsoft MVP
.Net Developer
Ambiguity has a certain quality to it.
 
J

Joerg Jooss

Rick said:
Ok, Thanks!

But do you know how I can add, programatically, the following line in
the HTML code: <meta http-equiv="refresh" content="600"> ?

Uh, why also these crappy META tags? You can do a Refresh in HTTP as
well -- though it's non-standard, it's widely supported.

Response.AppendHeader("Refresh", "600");

Cheers,
 

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,995
Messages
2,570,228
Members
46,818
Latest member
SapanaCarpetStudio

Latest Threads

Top