更改ASP.NET控件的访问修饰符 [英] Change the Access Modifiers of ASP.NET controls

查看:61
本文介绍了更改ASP.NET控件的访问修饰符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将控件放在这样的.aspx文件中;

If I put a control in a .aspx file like this;

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

我在页面的.aspx.designer.cs文件中获得了声明的控件;

I get a declared control in the page's .aspx.designer.cs file;

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

但是我想将控件的访问修饰符更改为 public .是否可以设置任何属性或类似属性来更改访问修饰符?

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

这是为什么,我想这样做.我正在尝试使跨页回发工作得井井有条.我有两页:

Here's why I want to do it. I am trying to have cross-page postbacks work nice and neatly. I have two pages:

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

SecondPage.aspx
    MyLabel : label

当用户单击FirstPage.MyButton时,我想将 FirstPage.MyTextBox.Text 的值写入 SecondPage.MyLabel.Text .我可以使用Page.FindControl做到这一点,但这似乎不能很好地替代将前一页转换为FirstPage对象并直接引用其上的MyTextBox控件.像这样的东西;

When the user clicks FirstPage.MyButton, I want to write the value of FirstPage.MyTextBox.Text into SecondPage.MyLabel.Text. I could do it with Page.FindControl, but this seems like a poor substitute to casting the previous page as a FirstPage object and referring directly to the MyTextBox control on it. Something like this;

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

是否可以更改访问修饰符?

Is there any way to change the access modifier?

推荐答案

您只需从设计器中删除声明,然后将其放在代码中即可.

You can just delete the declaration from the designer and put it in your code behind.

声明周围的注释表示要这样做.

The comments around the declaration say to do this.

/// To modify move field declaration from designer file to code-behind file.

这篇关于更改ASP.NET控件的访问修饰符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆