Pass data into .NET Web Part?

G

Guest

I have a aspx page that I want to pass data into dynamically created
webparts. Each web part will contain a user control I created
(WebUserControl1) that exposes a public property (.TestData). This property
then sets a label control on Web Part's user control....

WebUserControl1 mycontrol =
(WebUserControl1)LoadControl("WebUserControl1.ascx");
mycontrol .TestData= "test data passed to webpart's usercontrol";
mycontrol .ID = "control";

WebPart myWebPart = WebPartManager1.CreateWebPart(mycontrol);
myWebPart.Title = "Some Title";
WebPartManager1.AddWebPart(myWebPart, WebPartManager1.Zones[0], 0);

But when the page renders, the webpart is created in the zone, with the
title and user control, but the data passed seems to get lost and is never
setting the label inside.

What am I doing wrong? Thanks, Dave.
 

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

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,527
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top