Monday, November 22, 2004

ASP.NET: A reference to a webuser controls

Using webusercontrols gives great flexibility in building websites. Especially when you use in a dynamic way as shown in an early blog.

In designtime, however, you can not find a reference to a webusercontrol. In other words you won't find it in the control list of the object inspector. I'm not sure that this is common logic, however the solution is quit simple.

With the function FindControl, you can make a reference to a control and set it's properties.

procedure TWebForm1.SetMyWebUserControl;
var wuc : TWebUserControl1;
begin
wuc := FindControl('UserControl1') As TWebUserControl1;
If Assigned(wuc) then begin // Make sure it is there!
wuc.content := 'Got you!';
end;
end;

Where 'UserControl1' is the ID of the webusercontrol on the page.

No comments: