access modifier for webcontrols

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.
 
E

Eliahu

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top