1

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)

becomes

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

Except that there is no Control.IsPostBack?

How do i replace UserControl with Control?

Series

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

Community
  • 1
  • 1
Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219

1 Answers1

2

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 Reference

Tim M.
  • 53,671
  • 14
  • 120
  • 163