How to access the web page public variable from user control in asp .net ?

有帮助吗?

解决方案

Your page class derived from asp.net Page has this variable.

Every control has a Page property. If you know that this control will be placed on a particular class derived from Page, you can always cast it to the proper type. Then you have access to the public variable.

var propValue = ((MyControlBasePage)Page).MyProperty;

Ensure that the base class for the pages on which you use this control is Page derived form MyControlBasePage.

If you plan to use this on only one Page you could always directly use

var propValue = ((MyPage)Page).MyProperty;

But then, whats the user of a UserControl that you use on only one page.

其他提示

you can do like this:

<%= this.usercode %>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top