用户控件具有的IsPostBack,但控制不 [英] UserControl has IsPostBack, but Control does not

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

问题描述

我试图解决在Visual Studio中的一个bug,的建议是用户控件停止使用,并使用控制来代替。

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

所以我将所有我的用户控件逼到控制,例如:

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

我如何更换用户控件控制

这个问题是一个在正在进行的系列#1,模板的用户控件

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

  • 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?

推荐答案

控制有一个属性,该属性有一个的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参考

这篇关于用户控件具有的IsPostBack,但控制不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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