Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB.NET
|
VB.NET General VB.NET discussions for issues that don't fall into other VB.NET forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 20th, 2003, 04:44 AM
Authorized User
 
Join Date: Jun 2003
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Default Load User Controls at Runtime

Hi

I'm trying to load/instaniate a user control at runtime, I had done some work on this sometime ago but I'm having trouble remembering all the syntax.

I thought the assembly was loaded through "System.Reflection.Assembly.LoadFrom(<File Name & Path>). then create an object variable and assign the assembly to that object, which would then allow you to use the control. But I cannot get the object variable to instaniate with a copy of the assembly, and cannot find any examples that user a user control in this way, all the examples show how to retrieve parameters from the assembly which is not what I want to do.

Or is there another way to load a user control at runtime?

Regards


Duncan
__________________
Duncan
 
Old October 20th, 2003, 01:07 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

For the user control myUserControl.ascx with a codebehind class of myUserControl you would use something like this:

objMyControl = LoadControl("myUserControl.aspx"), myUserControl

If you need to manipulate properties on that control, you should convert it to the known control type.

objMyControl = CType(LoadControl("myUserControl.aspx"), myUserControl)
objMyControl.StringProperty = "hello world"
objMyControl.IntProperty = 8

Then you could add that to your form or some placeholder with:

<some control or the page>.Controls.Add(objMyControl)

Peter
 
Old November 4th, 2005, 03:25 PM
Authorized User
 
Join Date: Nov 2005
Posts: 15
Thanks: 1
Thanked 0 Times in 0 Posts
Default

In DS.ascx, I have 40 input controls like textboxes, dropdownlist, checkbox, etc. and save buttons etc....

I used this DS.ascx in another control (by dragging and dropping into) "UseDSControl.ascx" by using the following code:

UseDSControl.ascx.vb: g_ctlDS = LoadControl("ctlDS.ascx")

and then when I try to set the control default value (or) accessing values for textbox, it says txtname/chkallow not available. Because it's protected in ctlDS.ascx, I changed it to "public withevents txtname as textbox" but it automatically changes back.

see the following: how to do this in ctlUseDSControl.ascx.vb without writing public properities for each control to set/get values in ctlDS.ascx:

ctlUseDSControl.ascx.vb:

if g_ctlDS.chkAllow then
    'call function 1
else
    'call function 2
end if

g_ctllDS.txtName="ABC"

Please let me know ASAP.


Thanks for your help in advance.
 
Old November 4th, 2005, 07:05 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Cross post of http://p2p.wrox.com/topic.asp?TOPIC_ID=36335. Please see there for answer.

Can you please not cross-post? Also, picking a right forum for your question (e.g. not a book specific one, or general VB.NET but an ASP.NET forum) generally helps in getting a better answer.
Also, ASAP may not be the best way to trigger people to give you a quick answer.

Cheers,

Imar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Load User Controls Asynchronously everest ASP.NET 2.0 Professional 3 October 29th, 2007 08:00 AM
User controls' content: Chapter 2 User Controls AGS BOOK: Professional ASP.NET 2.0 Server Control and Component Development ISBN: 978-0-471-79350-2 10 July 26th, 2007 05:36 AM
Controls at runtime ITGeek ASP.NET 1.0 and 1.1 Basics 4 July 11th, 2007 05:23 AM
handling dynamic load of user controls spacky001 ASP.NET 1.0 and 1.1 Basics 1 December 16th, 2006 06:14 PM
Need urgent help loading user controls at runtime rpeters83 ASP.NET 2.0 Professional 7 September 3rd, 2006 10:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.