UserControl 有 IsPostBack,但 Control 没有 [英] UserControl has IsPostBack, but Control does not

查看:10
本文介绍了UserControl 有 IsPostBack,但 Control 没有的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试解决 Visual Studio 中的一个错误,the建议是停止使用 UserControls 并改用 Control..

i'm trying to solve a bug in Visual Studio, the suggestion is to stop using UserControls and use Control instead..

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

So i'm converting all my UserControl into just Control, e.g.:

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 系列中的一个,模板化用户控件":

This question is one in the ongoing Stackoverflow series, "Templating user controls":

推荐答案

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

Control has a Page property, which has an IsPostback property. This should give you the value you need.

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

MSDN 参考

这篇关于UserControl 有 IsPostBack,但 Control 没有的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆