User control in web part properties not initialized when added via catalogpart



I'm not sure what I'm doing wrong here...
I've created a web parts zone, and a catalog zone.

Now if I create a very simple user control called "Tester":

public partial class Tester : System.Web.UI.UserControl
public string Caption
get { return (string)ViewState["Caption"]; }
set { ViewState["Caption"] = value; }

public void Page_Load(object sender, EventArgs e)
Label1.Text = Caption;
, I can place this in my WebPartZone, add a 'Caption="Hello"'
attribute, and it shows up fine with the caption displayed correctly.

However, if I add it to a DeclarativeCatalogPart:

<uc1:Tester ID="mytester" runat="server" EnableViewState="true"
Title="MyTester" Caption="Hello" />

, then I add the part to the zone, the part is added, but the caption
does not appear. A closer inspection reveals that although Page_Load is
entered, Caption is null (and ViewState for the control is empty). This
seems to be because clicking "add" in the CatalogZone adds the user
control with a new control id "wpxxxxx", and this new control is not

Do I need to do anything special to get the catalogzone to instantiate
a new instance of my control properly, setting up all my properties?

Any help would be much appreciated!


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question