I'm working on a usernamerecovery server control that mimics the passwordrecovery control, except asks for an email, and sends the username. Like the passwordrecovery control, it will be use templates for the different views. I think I know the answer to
this, but I'm not sure of the reason...
Given the following container control, which is similar to the patterns used in many of the built-in controls:
private class Container : Control, INamingContainer
{
private TextBox userData;
public Control UserData
{
get
{
if (this.userData != null)
return this.userData;
return FindControl("UserData");
}
set { this.userData = value; }
}
private Label userDataLabel;
public Label UserDataLabel
{
get { return this.userDataLabel; }
set { this.userDataLabel = value; }
}
}
Why do certain controls explicitly try to find the control by ID, where others simply do not? It appears that only the controls for which some action has to take place are the ones that find the control by ID. Controls that do not locate by ID only seem
to do something when there is no user-supplied template. I would have expected the control builder to set the properties for the controls whose signatures match in markup and the container.
For instance, in the passwordrecovery control, if I set the UserNameLabelText property of the control, but define a UserNameTemplate in markup, that property does not get set. If I do not define the UserNameTemplate, it will get set to what I define.
Is this the expected behaviour? Are the non-findcontrol properties just for the non-templated, default instance?
jazzman42379
Member
191 Points
42 Posts
Template container control properties not getting set
Aug 04, 2006 03:54 PM|LINK
Hey All,
I'm working on a usernamerecovery server control that mimics the passwordrecovery control, except asks for an email, and sends the username. Like the passwordrecovery control, it will be use templates for the different views. I think I know the answer to this, but I'm not sure of the reason...
Given the following container control, which is similar to the patterns used in many of the built-in controls:
private class Container : Control, INamingContainer { private TextBox userData; public Control UserData { get { if (this.userData != null) return this.userData; return FindControl("UserData"); } set { this.userData = value; } } private Label userDataLabel; public Label UserDataLabel { get { return this.userDataLabel; } set { this.userDataLabel = value; } } }Why do certain controls explicitly try to find the control by ID, where others simply do not? It appears that only the controls for which some action has to take place are the ones that find the control by ID. Controls that do not locate by ID only seem to do something when there is no user-supplied template. I would have expected the control builder to set the properties for the controls whose signatures match in markup and the container.
For instance, in the passwordrecovery control, if I set the UserNameLabelText property of the control, but define a UserNameTemplate in markup, that property does not get set. If I do not define the UserNameTemplate, it will get set to what I define.
Is this the expected behaviour? Are the non-findcontrol properties just for the non-templated, default instance?
Thanks,
John