How to check if page is postback within reserved function pageLoad on ASP.NET AJAX

I'm seeking a means to examine within pageLoad() if this method is elevated throughout load occasion as a result of a postback/async postback or as a result of being filled and also accessibility the very first time.

This resembles Page.IsPostback building within code behind web page.

TIA,. Ricky

10
2022-06-07 14:37:53
Source Share
Answers: 9

Here is our Ajax matching to isPostback which we've been making use of for some time.

public static bool isAjaxRequest(System.Web.HttpRequest request)
    {//Checks to see if the request is an Ajax request
        if (request.ServerVariables["HTTP_X_MICROSOFTAJAX"] != null ||
            request.Form["__CALLBACKID"] != null)
            return true;
        else
            return false;
    }
0
2022-06-27 12:55:36
Source

@Dave Ward: Making use of RunOnce method functions flawlessly. This address my trouble without having the workaround to examine first if trainer currently exist prior to affixing to an occasion.

I'll note your solution as an approved solution. Many thanks once more.

0
2022-06-08 03:32:07
Source

Application.Init is possibly a better occasion to make use of, if you just desire the code to execute on the first load.

0
2022-06-08 03:05:19
Source

One means you can do that is to wire up an Application.Load trainer in Application.Init, after that have that trainer unbind itself after running:

Sys.Application.add_init(AppInit);

function AppInit() {
  Sys.Application.add_load(RunOnce);
}

function RunOnce() {
  // This will only happen once per GET request to the page.

  Sys.Application.remove_load(RunOnce);
}

That will certainly execute after Application.Init. It needs to be the last point prior to pageLoad is called.

6
2022-06-08 02:54:51
Source

@Dave Ward: This generally would function. Nonetheless, the code is to attach occasion on actions object. Due to the fact that the production of actions object takes place throughout Application.Init, affixing to that occasion will certainly bring about uncertain actions.

It will certainly behave if there is PostInit occasion.

0
2022-06-08 02:54:32
Source

You can still make use of Page.IsPostback throughout an async call.

0
2022-06-07 16:29:43
Source

@Darren: Thanks for the solution. I had actually attempted to create pageLoad with occasion argument ApplicationLoadEventArgs as parameter (see listed below). Nonetheless according to this:

The load occasion is elevated for all postbacks to the web server, that includes asynchronous postbacks.

As you have actually shown, the isPartialLoad building does not cover all postback circumstances. It'll behave if the occasion argument additionally have isPostback building.

   function pageLoad(sender, arg) {
      if (!arg.get_isPartialLoad()) {
          //code to be executed only on the first load
      }
   }

@mmattax: I'm seeking building that can be called from customer - side (javascript).

4
2022-06-07 16:26:04
Source

What you can do is wire approximately the load occasion of the Sys.Application class. you can after that make use of the isPartialLoad building of the Sys.ApplicationLoadEventArgs class. I think that would certainly allow you recognize if you remain in a async postback or otherwise.

To recognize if you remain in a blog post back, you'll need to take care of that in web server side code and also send out that to the customer.

2
2022-06-07 15:03:44
Source

You can have a surprise input that you ready to a well-known value on the web server side if it is a postback/callback - and also your javascript can examine that value.

That claimed, I actually wish that there patronizes - just remedy for this.

Edit: @mmattax - I think he is seeking a customer - side remedy - the JavaScript matching of that.

2
2022-06-07 15:03:27
Source