views:

341

answers:

3

I need to autopostback my page on the first load, and i need to wait the entire page have finish loading before post back the page.

I use in the page load

if (!IsPageWasPostBack)
      {
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "forcePostBack", "Sys.WebForms.PageRequestManager.getInstance().add_endRequest(postBackLoading);function postBackLoading(){__doPostBack('" + this.Page.ClientID + "','');}", true);
      }

IsPageWasPostBack is a viewstate variable.

When i put

Sys.WebForms.PageRequestManager.getInstance().add_endRequest

my page dont post back. If i remove it the page post back succesfully but to fast.

I dont want use timer to call back my post back.

Any idea ?

+2  A: 

you could use jquery and use $(document).ready($("#myform).submit();) or you could wait for the ready then have a timer in your javascript just to wait a few extra seconds.

minus4
It's working for the post back, but are to fast.
Cédric Boivin
I accept this answer but, i do it another way because my context is different, but this way are maybe a good way.
Cédric Boivin
A: 

What about waiting a few seconds?

$(document).ready(
   setTimeout('$("#myform).submit()',2000);
) ;
Daniel
I try to find another method than use timeout, i dont think this solutions is clean, beacause the result could not be the same on different computer.
Cédric Boivin
A: 

Have you tried using the LoadComplete event instead of the Load event?

Arturo Molina