How do I force a page to postback continually?

C

CW

I have written a chat console using DHTML/ASPX. One of the hidden frame
continuously refreshes and writes any new messages to a conversation
transcript frame. My problem is that I need to keep track of the last
message I have already written to the transcript frame, thus postback is
necessary (so that LastMessageID stored in the text property of a label
field can be read).

I have the following at <body> tag

<body onload="javascript:DoIt(<%=GetNewMessages()%>)"
MS_POSITIONING="FlowLayout">

where DoIt has the following definition

function DoIt(NewMessages)
{
top.ActualTranscript.document.write(NewMessages);
top.ActualTranscript.window.scrollTo(0,5000000);
setTimeout('Form1.submit',2000)
}


The idea is that the page posts back to itself every 2 seconds. However,
Form1.submit is actually not triggering anything at all. I don't exactly
know much about javascript. I would appreciate some help to get this to
work.

Thanks in advance
 
S

Shiva

Hi,

Is the form name Form1? Try (irrsepctive of the form name): setTimeout
("window.document.forms[0].submit();", 2000);

I have written a chat console using DHTML/ASPX. One of the hidden frame
continuously refreshes and writes any new messages to a conversation
transcript frame. My problem is that I need to keep track of the last
message I have already written to the transcript frame, thus postback is
necessary (so that LastMessageID stored in the text property of a label
field can be read).

I have the following at <body> tag

<body onload="javascript:DoIt(<%=GetNewMessages()%>)"
MS_POSITIONING="FlowLayout">

where DoIt has the following definition

function DoIt(NewMessages)
{
top.ActualTranscript.document.write(NewMessages);
top.ActualTranscript.window.scrollTo(0,5000000);
setTimeout('Form1.submit',2000)
}


The idea is that the page posts back to itself every 2 seconds. However,
Form1.submit is actually not triggering anything at all. I don't exactly
know much about javascript. I would appreciate some help to get this to
work.

Thanks in advance
 
C

CW

Thanks, I have tried that without any success. Form1 is the correct name
because intellisense was able to display a list of methods (including
submit) as I typed it in in the javascript block.
 
S

Shiva

Hi,
Make sure the first two lines in DoIt() do not produce any script errors. As
a quick check comment-out the first two lines and check the form is
submited. Also have () after submit as it is a method.

Thanks, I have tried that without any success. Form1 is the correct name
because intellisense was able to display a list of methods (including
submit) as I typed it in in the javascript block.
 
C

CW

I got the form to resubmit by putting Form1.submit after the body
tagaltogether.

DoIt block is defined in <header> tag in a script block. After i removed the
submit statement and put it in its own script block that comes after body
tag altogether, form is now resubmitting.

However, it's not picking up a textbox text property value when it
resubmits. The page and control has viewstate enabled. I think it might have
someting to do with passing __VIEWSTATE in the javascript. Any idea how to
achieve that?

thanks

Shiva said:
Hi,
Make sure the first two lines in DoIt() do not produce any script errors.
As
a quick check comment-out the first two lines and check the form is
submited. Also have () after submit as it is a method.

Thanks, I have tried that without any success. Form1 is the correct name
because intellisense was able to display a list of methods (including
submit) as I typed it in in the javascript block.


Shiva said:
Hi,

Is the form name Form1? Try (irrsepctive of the form name): setTimeout
("window.document.forms[0].submit();", 2000);

I have written a chat console using DHTML/ASPX. One of the hidden frame
continuously refreshes and writes any new messages to a conversation
transcript frame. My problem is that I need to keep track of the last
message I have already written to the transcript frame, thus postback is
necessary (so that LastMessageID stored in the text property of a label
field can be read).

I have the following at <body> tag

<body onload="javascript:DoIt(<%=GetNewMessages()%>)"
MS_POSITIONING="FlowLayout">

where DoIt has the following definition

function DoIt(NewMessages)
{
top.ActualTranscript.document.write(NewMessages);
top.ActualTranscript.window.scrollTo(0,5000000);
setTimeout('Form1.submit',2000)
}


The idea is that the page posts back to itself every 2 seconds. However,
Form1.submit is actually not triggering anything at all. I don't exactly
know much about javascript. I would appreciate some help to get this to
work.

Thanks in advance
 
S

Steven Cheng[MSFT]

Hi CW,

AS for getting the new posted value in the textbox , here are some of my
suggestions:

Are you using the asp.net's TextBox server control or the HtmlInputText
control or
a normal <input type=text...> html element ? Anyway, we don't need to
manually post back the viewstate

I think we can check the following things:

1.If you're using the TExtBox server control <asp:TextBox ..> or
HtmlInputText control
<input type=text runat=server...>
we can directly access it via
id in the serverside code behind

2. if he is using normal <input type=text ...> html element, we can
access it's new postd value in the Request.Form collection
for example , if we have the following textbox in th form,

<input type=text name="username" >

Then,when the page is post back, we can use the Request.Form["username"] to
get its value.
#note that request.Form collection will identify the different items via
their "name" attribute in the html

In addition, make sure that the TextBox or <input type=text ..> are within
the <form > tag. And here is a simple test page which put some textboxes on
it and access their value when post back , you may also have a test:

=========aspx page=======================
<HTML>
<HEAD>
<title>postbackscript</title>
<script language="javascript">
function autopost()
{
window.setTimeout("document.forms[0].submit()",2000);
}
</script>
</HEAD>
<body onload="autopost();">
<form id="Form1" method="post" runat="server">
<table width="100%" align="center">
<tr>
<td height="21">
<asp:TextBox id="txtServer" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td><INPUT id="txtInputText" type="text" size="1" name="txtInputText"
runat="server"></td>
</tr>
<tr>
<td><INPUT id="txtNormalInput" type="text" name="txtNormalInput"></td>
</tr>
</table>
</form>
</body>
</HTML>

===============code behind==========================
public class postbackscript : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtServer;
protected System.Web.UI.HtmlControls.HtmlInputText txtInputText;

private void Page_Load(object sender, System.EventArgs e)
{
if(IsPostBack)
{
Response.Write("<br>Page is post back at: " +
DateTime.Now.ToLongTimeString());
Response.Write("<br>txtServer's post value is: " + txtServer.Text);
Response.Write("<br>txtInputText's post value is: " +
txtInputText.Value);
Response.Write("<br>txtNormalInput's post value is: " +
Request.Form["txtNormalInput"]);
}
}
.................................

}

==================================


Hope helps. If you still have anything unclear, please feel free to post
here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Shiva

Hi,

Is the textbox a server-side control (runat=server) or is it not? As Steven
suggested, based on how you have defined your text box, you have to use
either Request.Form collection or refer to the textbox directly to get the
text value.

HTH

I got the form to resubmit by putting Form1.submit after the body
tagaltogether.

DoIt block is defined in <header> tag in a script block. After i removed the
submit statement and put it in its own script block that comes after body
tag altogether, form is now resubmitting.

However, it's not picking up a textbox text property value when it
resubmits. The page and control has viewstate enabled. I think it might have
someting to do with passing __VIEWSTATE in the javascript. Any idea how to
achieve that?

thanks

Shiva said:
Hi,
Make sure the first two lines in DoIt() do not produce any script errors.
As
a quick check comment-out the first two lines and check the form is
submited. Also have () after submit as it is a method.

Thanks, I have tried that without any success. Form1 is the correct name
because intellisense was able to display a list of methods (including
submit) as I typed it in in the javascript block.


Shiva said:
Hi,

Is the form name Form1? Try (irrsepctive of the form name): setTimeout
("window.document.forms[0].submit();", 2000);

I have written a chat console using DHTML/ASPX. One of the hidden frame
continuously refreshes and writes any new messages to a conversation
transcript frame. My problem is that I need to keep track of the last
message I have already written to the transcript frame, thus postback is
necessary (so that LastMessageID stored in the text property of a label
field can be read).

I have the following at <body> tag

<body onload="javascript:DoIt(<%=GetNewMessages()%>)"
MS_POSITIONING="FlowLayout">

where DoIt has the following definition

function DoIt(NewMessages)
{
top.ActualTranscript.document.write(NewMessages);
top.ActualTranscript.window.scrollTo(0,5000000);
setTimeout('Form1.submit',2000)
}


The idea is that the page posts back to itself every 2 seconds. However,
Form1.submit is actually not triggering anything at all. I don't exactly
know much about javascript. I would appreciate some help to get this to
work.

Thanks in advance
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top