Simple javascript postback fails

Simple javascript postback fails

Post by Deanna Delapass » Sat, 12 Jan 2002 00:00:43



Hi,

   I'm trying to force a Page_Load from a client javascript :
  function refreshWindow() {
   alert("in refresh");
   __doPostBack("TimeLabel","");
  }

   TimeLabel is the name of a button on the page.  The script fails with
"... expecting object".  Can someone tell me what's wrong?  I also tried
using single quotes, that didn't work either.

Thanks,
Deanna
(html below)

Page_Load:
TimeLabel.Text = Now

HTML:


Codebehind="WebForm8.aspx.vb" Inherits="tkt.WebForm8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
 <HEAD>
  <title></title>
  <meta name="GENERATOR" content="Microsoft Visual

Studio.NET 7.0">
  <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
  <meta name="vs_defaultClientScript" content="JavaScript">
  <meta name="vs_targetSchema"
content="http://schemas.microsoft.com/intellisense/ie5">
  <script>
  function window_onload() {
   alert("in onload");
   window.setInterval("refreshWindow()", 5000);
   }
  function refreshWindow() {
   alert("in refresh");
   __doPostBack("TimeLabel","");
  }
  </script>
 </HEAD>
 <body MS_POSITIONING="GridLayout" onload="return

window_onload();">
  <form id="Form1" method="post" runat="server">
   <asp:Button id="Button1" style="Z-INDEX:

101; LEFT: 182px; POSITION: absolute; TOP: 119px" runat="server"

Text="Button"></asp:Button>
   <asp:Label id="TimeLabel" style="Z-INDEX:

102; LEFT: 186px; POSITION: absolute; TOP: 71px" runat="server"

Width="276px" Height="19px">Label</asp:Label>
  </form>
 </body>
</HTML>

 
 
 

Simple javascript postback fails

Post by MS » Sat, 12 Jan 2002 04:26:16



Quote:> Hi,

>    I'm trying to force a Page_Load from a client javascript :
>   function refreshWindow() {
>    alert("in refresh");
>    __doPostBack("TimeLabel","");
>   }

>    TimeLabel is the name of a button on the page.  The script fails with
> "... expecting object".  Can someone tell me what's wrong?  I also tried
> using single quotes, that didn't work either.

Hi,

The problem is that there is no __doPostBack function on the page. You need
to have a runat=server control that uses PostBack (such as an input
type=button) on your page.

Single quotes and double quotes both delimit strings in JScript.

Peter

--

Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
Please post all questions to the group. Thanks.

 
 
 

Simple javascript postback fails

Post by Deanna Delapass » Sat, 12 Jan 2002 05:59:31


Hi Peter,

   There IS a button on the page (see complete html excerpt in my original
post) for that very reason.   Is it not setup correctly?

<asp:Button id="Button1" style="Z-INDEX:101; LEFT: 182px; POSITION:
absolute; TOP: 119px" runat="server"
Text="Button"></asp:Button>

Thanks very much,
Deanna





> > Hi,

> >    I'm trying to force a Page_Load from a client javascript :
> >   function refreshWindow() {
> >    alert("in refresh");
> >    __doPostBack("TimeLabel","");
> >   }

> >    TimeLabel is the name of a button on the page.  The script fails with
> > "... expecting object".  Can someone tell me what's wrong?  I also tried
> > using single quotes, that didn't work either.

> Hi,

> The problem is that there is no __doPostBack function on the page. You
need
> to have a runat=server control that uses PostBack (such as an input
> type=button) on your page.

> Single quotes and double quotes both delimit strings in JScript.

> Peter

> --

> Waiting for the Vengabus? http://www.microsoft.com/info/cpyright.htm
> Please post all questions to the group. Thanks.

 
 
 

Simple javascript postback fails

Post by Tess Norland » Sat, 12 Jan 2002 07:32:53


Hi Deanna,

The short answer to your question is you are getting the object expected
error message because your page does not contain a
__doPostBack method. If you do view source on the page you can verify this.
If it did have a __doPostBack method you could actually give it "bla","bla"
as parameters if you only wanted to repost the page.

The __doPostBack method only gets added to the page if it will be used,
i.e. if you have any controls on the page (for example a textbox) that will
do autopostback. In your code you didnt have any controls like that. The
parameters to the __doPostBack method are the control and the event you
want to fire on postback and I dont think that thats exactly what you are
looking to do since you are giving it a label as the first parameter and a
label doesnt have any events.

So I think that you are basically trying to kill a fly with a bulldozer:)
if you only want to repost the page and get the page_load to fire you can
simply call Form1.submit() from your refreshWindow() method that should
repost the page and fire the page_load event.

Hope this helps.

Tess

This posting is provided AS IS with no warranties, and confers no rights.