473,471 Members | 1,938 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Dynamically adding usercontrols

I'm quite new to ASP.NET so please forgive me if this is a silly question but
I'm completely stuck!

I'm trying to dynamically add a UserControl to a web form. My control is in
a file called Customers.ascx so I'm using:

Dim myControl as UserControl
myContol = LoadControl("Customers.ascx")

I then want to assign a value to the CustomerID property of the control but,
obviously, becasue the variable is of type UserControl there is no CustomerID
property.

What type should the myControl variable be? Or am I going about this
completely wrongly?

I'm using VB.NET in Visual Studio 2003, if that makes any difference.

Any help you can give would be greatly appreciated.

Alan
Nov 18 '05 #1
1 1230
You are going about it correctly. What type it should be is the type of the
control..which, my guess is Customer

If you go into your codebehind, you'll see something like

Public Class Customer
Inherits UserControl
...

So...

Dim myControl as Customer
myControl = ctype(LoadControl("Customer.ascx", Customer)
myControl.CustomerId = 123

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Alan Lambert" <Al*********@discussions.microsoft.com> wrote in message
news:C9**********************************@microsof t.com...
I'm quite new to ASP.NET so please forgive me if this is a silly question but I'm completely stuck!

I'm trying to dynamically add a UserControl to a web form. My control is in a file called Customers.ascx so I'm using:

Dim myControl as UserControl
myContol = LoadControl("Customers.ascx")

I then want to assign a value to the CustomerID property of the control but, obviously, becasue the variable is of type UserControl there is no CustomerID property.

What type should the myControl variable be? Or am I going about this
completely wrongly?

I'm using VB.NET in Visual Studio 2003, if that makes any difference.

Any help you can give would be greatly appreciated.

Alan

Nov 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Emma | last post by:
Hi, I'm developing a GUI with almost all Usercontrols. It's been working wonderfull up till a few weeks ago, and really crashed yesterday. Suddenly I can no longer add some of my usercontrols...
1
by: kanones | last post by:
Hi - I am seeing some performance degradation when I am loading a control dynamically onto a page with multiple other dynamical controls using Page.LoadControl versus dragging and dropping it...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
2
by: Mark | last post by:
Hi, I am wanting to know if it is possible to embed a UserControl into a Page at runtime. What I am trying to do is allow a user to specify that they want a "contact form" or a "latest news" in...
2
by: Vivek Sharma | last post by:
Hi There, I have a situation where I wish to load the controls dynamically on the basis of user role. Hence, I am using this code. if (UserRole == "IS Administrator") { Control UC1 =...
5
by: marfi95 | last post by:
I have a form that has a left and right panel. In the left panel is a treeview. The right panel I want to change dynamically based on the type of node selected. What I'm doing is loading the...
7
by: =?Utf-8?B?Li46OiBLZXZpbiA6Oi4u?= | last post by:
I have a problem with accessing controls that I have loaded dynamically and added to a web page. The scenario: I have a webpage that displays multiple instances of a user control on the page. ...
7
by: Nathan Sokalski | last post by:
I have a page which I dynamically add several usercontrols (*.ascx files) to using the following code: Public Sub Refresh() For Each section As DataRow In Me.GetSections().Rows...
0
by: boysenberry | last post by:
Hi. I have a user control which I need to add to a page several times. This works fine and the user control provides the functionality I need. However, I also need to access properties and methods...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.