bgs
bgs

Reputation: 3223

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

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

Upvotes: 2

Views: 4655

Answers (2)

nunespascal
nunespascal

Reputation: 17724

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.

Upvotes: 3

Altaf Sami
Altaf Sami

Reputation: 846

you can do like this:

<%= this.usercode %>

Upvotes: 1

Related Questions