Som...">

Modify ASP.NET Control Access Modifiers

If I put the control in an .aspx file, for example:

<asp:TextBox ID="protectedTextBox" runat="server">Some info</asp:TextBox> 

I get the declared control in the .aspx.designer.cs file.

 protected global::System.Web.UI.WebControls.TextBox protectedTextBox; 

But I would like to change the access modifier of the control to public . Is there any attribute or similar parameter that I can change to change the access modifier?

That is why I want to do this. I try to work with cross-mails well and accurately. I have two pages:

 FirstPage.aspx MyTextBox : textbox MyButton : button, @PostbackUrl=Secondpage SecondPage.aspx MyLabel : label 

When the user clicks the FirstPage.MyButton button, I want to write the value of FirstPage.MyTextBox.Text to SecondPage.MyLabel.Text . I could do this using Page.FindControl, but it seems like a bad replacement for the previous page as a FirstPage object and refers directly to the MyTextBox control. Something like that;

 // on the page_load of SecondPage.aspx; var previousPage = this.PreviousPage as FirstPage; this.MyLabel.Text = previousPage.MyTextBox.Text; 

Is there a way to change the access modifier?

+6
access-modifiers c # controls
source share
3 answers

You can simply remove the ad from the designer and place it in your code.

The commentary on the statement says so.

 /// To modify move field declaration from designer file to code-behind file. 
+6
source share

One of the options I looked at is a public property that provides the original page;

 public TextBox PublicTextBox { get { return this.MyTextBox; } } 

Which would do the job, but it seems hacked.

+2
source share

Steve exposing the page controls will make sense if you need to control these controls, but in your case you just need to pass some data (this line) to another handler, so I would expose this, not the control itself.

+1
source share

All Articles