Reputation: 3043
Is there a way I can find out if a Page has been posted back without using the Page object. I want to know if the page has been posted back without passing a parameter to the function, like you can check the Request object by using httpContext.Current.Request , is there a Page equivalent? The check occurs in a library function?
Upvotes: 5
Views: 1011
Reputation: 52260
Here's another technique. You can get the Page from HttpContext, and check its IsPostBack method. That way you don't have to pass the page or an IsPostBack flag to your helper function.
void MyHelperFunction()
{
Page page = HttpContext.Current.Handler as Page;
bool isPostBack = (page != null) && (page.IsPostBack);
}
Upvotes: 3
Reputation: 1643
If you're only trying to avoid using the Page property, and not the Page class, you can cast HttpContext.Current.Handler to a Page object in the context of a standard page request.
Upvotes: 2