Sunday, November 19, 2006

Web Controls Access Modifiers ASP.Net 2.0

In ASP.Net 1.x, when you drag a new web-control to the page, the controls declaration would be added to the code behind as follows:

protected TextBox txtTest;

On ASP.Net 2.0, the control definition is in-accessible, hence in order to change the modifier of a specific control, you must encapsulate it inside a property or a method, i.e:
public TextBox txtTest
{
get {return _txtTest;}
set {_txtTest=value; }
}

On one hand, yeah this pretty stinks, but on the other it makes more sense, I mean after all what's the difference between a control and a private member?

No comments: