简体   繁体   English

没有Page的ASP.NET IsPostBack

[英]ASP.NET IsPostBack without Page

Is there a way I can find out if a Page has been posted back without using the Page object. 有没有办法可以找出一个页面是否在不使用Page对象的情况下被回发。 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? 我想知道页面是否已经回传而没有将参数传递给函数,就像你可以使用httpContext.Current.Request检查Request对象,是否有一个Page等效? The check occurs in a library function? 检查发生在库函数中?

如果您只是试图避免使用Page属性而不是Page类,则可以在标准页面请求的上下文中将HttpContext.Current.Handler强制转换为Page对象。

Here's another technique. 这是另一种技术。 You can get the Page from HttpContext, and check its IsPostBack method. 您可以从HttpContext获取Page,并检查其IsPostBack方法。 That way you don't have to pass the page or an IsPostBack flag to your helper function. 这样您就不必将页面或IsPostBack标志传递给辅助函数。

void MyHelperFunction()
{   
    Page page = HttpContext.Current.Handler as Page;
    bool isPostBack = (page != null) && (page.IsPostBack);
}

Yep 是的

  1. Check to see if the HTTP verb is POST 检查HTTP动词是否为POST
  2. Check the Forms collection for a value associated with "__PREVIOUSPAGE" 检查Forms集合中是否有与“__PREVIOUSPAGE”关联的值

See also here 另见这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM