Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

Dynamically Added User Control

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Jenni.Haughton@googlemail.com - 08 Jun 2007 17:42 GMT
I have a solution with 2 projects in it.  I need to programatically
add a user control from one project into the other one (as you cannot
declare this normally on the form because it is in a different
application). When the page_load event of the user control is fired at
run-time, none of the form objects on the user control exist.

Is this a namespace issue? Or can you just not share a user control
over 2 projects without having a copy in both projects.

Thanks,
Jenni
Lloyd Sheen - 08 Jun 2007 17:57 GMT
>I have a solution with 2 projects in it.  I need to programatically
> add a user control from one project into the other one (as you cannot
[quoted text clipped - 7 lines]
> Thanks,
> Jenni

This should be easy.  I would create a third project for the usercontrol.
Then from each of the other projects either reference the usercontrol
assembly or the usercontrol project depending on the level of debugging you
are doing.  Then when the usercontrol has changes the other two projects
will automatically pick up the new version (if you open the projects and
build the project).

Hope this helps,
Lloyd Sheen
Jenni.Haughton@googlemail.com - 08 Jun 2007 18:09 GMT
Thanks for the post.
The trouble is accessing the user control once it is in a seperate
project.  I can reference it ok, but at run-time the control within
the user control do not exist.

Thanks,
Jen
Lloyd Sheen - 08 Jun 2007 18:58 GMT
> Thanks for the post.
> The trouble is accessing the user control once it is in a seperate
[quoted text clipped - 3 lines]
> Thanks,
> Jen

Do you mean that you have multiple controls within your usercontrol?

If so you must provide the method of accessing the controls.  This can be
done with functions or readonly properties.

Hope this helps
Lloyd Sheen
Jenni.Haughton@googlemail.com - 11 Jun 2007 14:12 GMT
> Do you mean that you have multiple controls within your usercontrol?
>
> If so you must provide the method of accessing the controls.  This can be
> done with functions or readonly properties.

I have form objects such as labels and text boxes in the user control
which I need to access.  Here is my code -

HTML in user control -
<asp:image Height="33" AlternateText="Powered by WorldPay" Width="139"
ImageAlign="AbsMiddle" Runat="server" ID="imageWorldPay"></asp:image>

Code that gives the error in the code behind of the UC -
imageWorldPay.ImageUrl = "~/images/poweredbyworldpay.gif";

Code in the other project which loads the uc -
protected System.Web.UI.Control pricegridcontrol;
pricegridcontrol = new
LumleyJacobsSharedLibrary.controls.BuyingProcessPriceGrid();
wlnav_pricegrid.Controls.Add(pricegridcontrol);

The code in the user control to set the ImageUrl does not work because
the label does not seem to exist.  Is this a;ways the case when
dynamically adding user controls, or is there another way?

Thanks,
Jen

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.