User555856731 posted
Hi,
I am trying to create a custom control in VS 2005, it contains 3 textfields that are populated from an external object provided through a method.
The markup is simply
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="PersonInfo.ascx.cs" Inherits="UserManagement.PersonInfo" %>
<div>
<asp:TextBox ID="txtbox_Name" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtbox_Title" runat="server"></asp:TextBox><br />
<asp:TextBox ID="txtbox_Mobile" runat="server"></asp:TextBox>
</div>
and the codebehind looks like this (imports excluded):
public partial class PersonInfo : System.Web.UI.UserControl
{
public string Name { get { return txtbox_Name.Text; } private set { txtbox_Name.Text = value; } }
public string Title { get { return txtbox_Title.Text; } private set { txtbox_Title.Text = value; } }
public string Mobile { get { return txtbox_Mobile.Text; } private set { txtbox_Mobile.Text = value; } }
protected void Page_Load(object sender, EventArgs e)
{
}
public void SetValues(Person person)
{
Name = string.Format("{0} {1}", person.Fornavn, person.Etternavn);
Mobile = person.Mobil;
Title = person.Title;
}
}
I've tried to set a breakpoint on both Page_Load and SetValues method, but when the execution enters these methods, the child controls: txtbox_Name, txtbox_Title and txtbox_Mobile are all null. I have also tried to invoke EnsureChildControls in the Page_Load
method, without any luck.
My question is simply put, how do I get these controls to be initialized, so I can set their values?
Any help would be greatly appreciated.