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?
Asked
Active
Viewed 882 times
5
-
Although you can do this, you probably don't want to. This is usually a sign that code needs refactoring. – moarboilerplate Jun 23 '15 at 21:31
3 Answers
3
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);
}

John Wu
- 50,556
- 8
- 44
- 80
2
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.

moarboilerplate
- 1,633
- 9
- 23