加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – UserControl有IsPostBack,但是Control没有

发布时间:2020-12-16 00:07:35 所属栏目:asp.Net 来源:网络整理
导读:我正在尝试解决Visual Studio中的错误,the suggestion is to stop using UserControls and use Control instead.. 所以我将我的所有UserControl转换为Control,例如: public partial class Controls_UserManagement_GroupManager : System.Web.UI.UserContro
我正在尝试解决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?

如何用Control替换UserControl?

系列

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

> How to add a Templating to a UserControl?
> How to inherit from Control,rather than UserControl?
> UserControl has IsPostBack,but Control does not
> UserControl does not have public property named ContentTemplate
> How do i specify CodeFileBaseClass from web.config?

解决方法

Control有一个Page属性,它有一个IsPostback属性.这应该为您提供所需的价值.
public class MyControl : Control{
    protected override void OnInit( EventArgs e ){
        if( this.Page.IsPostBack ){
            // do something
        }
    }
}

MSDN Reference

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读