access modifier for webcontrols

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am modifing the web app creted by someone else , I see that in code behind
file all the web controls declared as public to access then in different
class. Now I know its bad pactice but I have noticed something wierd when
ever I try to add new webcontrol to that page all the web controls which are
declared as public change back to protected I cant understand this behaviour
can someone expalin this.

Thanks and regards.
 
The reason for this is that the code-behind page is partially rebuilt each
time you touch the design of your aspx page. In order to stop that, I'd
suggest you rename the controls, say, using _1 postfix, and create the
public get properties having the old names.

For example,

in old code:

public Button Button1;

in new code:

protected Button Button1_1;

public Button Button1 {
get { return Button1_1; }
}

hope it helps.
 
Back
Top