accessing the base Page elements

  • Thread starter Thread starter Davíð Þórisson
  • Start date Start date
D

Davíð Þórisson

hi
I'm having great problems at this simple task; accessing elements on the
base page from my code behind various user controls. For example I have the
default.aspx page and in the @Page directive I use ClassName="default_aspx"
so I would have thought that to access a Label server control with
id="myLabel" I'd use

default_aspx.myLabel.text = "my text";

well it doesn't work!
 
The Page property of your Controls and Page instance points to a baseclass
of type System.Web.UI.Page. In order to get hold of your public properties
(controls etc.), you'll have to cast the Page instance to your own type:

((default_aspx) this.Page).myLabel.Text = "My Text";

Not sure this is what you were looking for, but then again, you might have
learned something new :-)
 
thx Anders will look into this
I haven't seen before this syntax where you put default_aspx into
parenthesis... what is that???
Seen the same when parsing custom sections from the web configuration file:

NameValueCollection sampleConfig = (NameValueCollection) ----------here ???
ConfigurationSettings.GetConfig("myDepartmentGroup/mySection");
string strKeyValue = (string)sampleConfig["myKey"]; --------- again with
string???
 
Back
Top