Hey, I am working on a web control (ascx) and there are various private properties/feilds that are declared, but when I assign them values, they don't seems to get them (see example below):
[C#]
public class dome : ...
{
-private string m_dome;
-public string f_dome;
-
-public string Dome
-{
--get
--{
---return m_dome;
--}
--set
--{
---m_dome = value;
--}
-}
...
-Page_load(..)
-{
--f_dome = "Hello";
--Dome = "Bye";
--Response.WriteLine(f_dome + ' ' + Dome);
-}
}
If I run the code and try to display the vars inside the class, nothing shows up. When I trace the app in debug mode, the f_dome and Dome are null after they are assigned values!
What gives?!
}

1 answers
That page_load isn't being called. You either need to put the call to Page_load in the constructor or after constructing, call domeobjectname.Page_load();
Hope that helps!
answered 2 years ago by:
0
EEP! vbguyny! Repeat after me! NO PUBLIC FIELDS!!!! Also, Pascal case on classes, properties, methods, CamelCase on fields!
OK, now that I got that off my chest.... ;)
I think the problem is probably that you are using these before they are instantiated, because controls don't instantiate the same way pages do.
You need to override CreateChildControls() in your control. I can't get to VS.Net right now, or I'd try to point you to an example.
Also, in your properties, you need to call EnsureChildControls() before setting values.
public string Dome {
get {
EnsureChildControls();
return _dome; //I like this notation, too..it's what MS uses.
}
set {
EnsureChildControls();
_dome = value;
}
}
Hope this helps!
answered 2 years ago by:
0
Firstly, The page_load method is being called, I place breakpoints almost everywhere in the code. Lines are encountered, but no values are set.
Secondly, I'll try your suggest, Chads and get back to you.
answered 2 years ago by:
0
Sorry, Chads, tryed what you suggested but no succuss.
answered 2 years ago by:
0
Hmm...I'll ask around. I had the same problem, but the EnsureChildControls() fixed it.
And, you can call me Chad. :)
answered 2 years ago by:
0
Ok. Found a strange solution, I changed the property block to a public field (I know, Chad). Good thing it's not my app ;)
answered 2 years ago by:
0
As long as we agree that the solution to the problem doesn't technically make any sense... :)
Take care, bud!
answered 2 years ago by:
0
This post was imported from csharpfriends, if you have a similiar question please ask it again.
All previous members have been migrated, hope you enjoy the new platform!