【问题标题】:UserControl has IsPostBack, but Control does notUserControl 有 IsPostBack,但 Control 没有
【发布时间】:2012-09-01 13:04:35
【问题描述】:

我正在尝试解决 Visual Studio 中的一个错误,the suggestion is to stop using UserControls and use Control instead.

所以我将我所有的 UserControl 转换为 Control,例如:

public partial class Controls_UserManagement_GroupManager : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)

变成

public partial class Controls_UserManagement_GroupManager : System.Web.UI.Control
{
    protected void Page_Load(object sender, EventArgs e)
    {
       if (!IsPostBack)

除了没有Control.IsPostBack吗?

如何将UserControl 替换为Control

系列

这个问题是 Stackoverflow 系列中的一个,“模板化用户控件”

【问题讨论】:

    标签: asp.net user-controls


    【解决方案1】:

    Control 有一个Page 属性,它有一个IsPostback 属性。这应该会为您提供所需的价值。

    public class MyControl : Control{
        protected override void OnInit( EventArgs e ){
            if( this.Page.IsPostBack ){
                // do something
            }
        }
    }
    

    MSDN Reference

    【讨论】:

      猜你喜欢
      • 2015-09-09
      • 2014-10-21
      • 2018-03-14
      • 2010-10-29
      • 1970-01-01
      • 2018-04-22
      • 1970-01-01
      • 2016-05-11
      • 2018-11-11
      相关资源
      最近更新 更多