473,799 Members | 3,061 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Setting an object to a User Control

If I have a name of a User Control in my project, how can I set an Object to
that User Control?

ie;

I have a User Control, called "Accounts" in my project
I tried the following code

strUserControlN ame = "Accounts"
frmMain.Control s.Add(strUserCo ntrolName)

But, of course, the above code doesn't work, because the second line of code
wants a User Control parameter, not a string parameter.

so, I need to do something like this:

dim objUserControl as UserControl
set objUserControl = UserControl(str UserControlName )

How do I do this? Your help would be appreciated.
Dave

Mar 1 '06 #1
3 1470
private Accounts myAccount;

myAccount = new Accounts();

frmMain.control s.Add(myAccount );

This shouldn't have any problem.

Tedmond

"Dave" wrote:
If I have a name of a User Control in my project, how can I set an Object to
that User Control?

ie;

I have a User Control, called "Accounts" in my project
I tried the following code

strUserControlN ame = "Accounts"
frmMain.Control s.Add(strUserCo ntrolName)

But, of course, the above code doesn't work, because the second line of code
wants a User Control parameter, not a string parameter.

so, I need to do something like this:

dim objUserControl as UserControl
set objUserControl = UserControl(str UserControlName )

How do I do this? Your help would be appreciated.
Dave

Mar 2 '06 #2
Sorry, yours is in VB verion.

Dim myAccount As Accounts
myAccount = New Accounts
frmMain.Control s.Add(myAccount )

"Tedmond" wrote:
private Accounts myAccount;

myAccount = new Accounts();

frmMain.control s.Add(myAccount );

This shouldn't have any problem.

Tedmond

"Dave" wrote:
If I have a name of a User Control in my project, how can I set an Object to
that User Control?

ie;

I have a User Control, called "Accounts" in my project
I tried the following code

strUserControlN ame = "Accounts"
frmMain.Control s.Add(strUserCo ntrolName)

But, of course, the above code doesn't work, because the second line of code
wants a User Control parameter, not a string parameter.

so, I need to do something like this:

dim objUserControl as UserControl
set objUserControl = UserControl(str UserControlName )

How do I do this? Your help would be appreciated.
Dave

Mar 2 '06 #3


"Tedmond" wrote:
Sorry, yours is in VB verion.

Dim myAccount As Accounts
myAccount = New Accounts
frmMain.Control s.Add(myAccount )

"Tedmond" wrote:
private Accounts myAccount;

myAccount = new Accounts();

frmMain.control s.Add(myAccount );

This shouldn't have any problem.

Tedmond

"Dave" wrote:
If I have a name of a User Control in my project, how can I set an Object to
that User Control?

ie;

I have a User Control, called "Accounts" in my project
I tried the following code

strUserControlN ame = "Accounts"
frmMain.Control s.Add(strUserCo ntrolName)

But, of course, the above code doesn't work, because the second line of code
wants a User Control parameter, not a string parameter.

so, I need to do something like this:

dim objUserControl as UserControl
set objUserControl = UserControl(str UserControlName )

How do I do this? Your help would be appreciated.
Dave


While that will work, the problem is, Tedmond, I have about 30 different
user controls that the user can choose from. The thing I'm trying to avoid is
setting up a Select statement with 30 choices in it. What I'm trying to find
is a way, based on a string containing the exact name of the user control, to
generate the form.controls.a dd(usercontrol) statement out of it.

I need something like:

dim gUserControl as UserControl
gUserControl = MyProject.Compo nent(StringName OfUserControl)
Form.Controls.A dd(gUserControl )

But, I need some correct syntax for that middle line of code. That's what I
don't know how to do.
Mar 2 '06 #4

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

Similar topics

0
1014
by: Amir Eshterayeh | last post by:
Dear Friends Hope things goes well to you. I have this problem. Would you please give me your solution? I want to change a property that I define on my user control in my web form that contains that user control. but when I want to set the property of user control at my web form, got this error c:\inetpub\wwwroot\test4\WebForm1.aspx.vb(19): Name 'Uc1' is not declared. How can I solve this problem. Please help.
1
2071
by: Roman | last post by:
I have built a simple user control that contains 2 buttons, a text box and a dropdownlist. When a button is clicked it sets the visible property of the textbox/dropdownlist and the button. ie the buttons allow me to toggle between the textbox and the dropdownlist. This works fine when the control is placed on the page but when it is placed inside a datalist, ie the itemtemplate, the onclick events for the buttons fire but the visibility...
18
18433
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on a remote update of tables and fields and can't find enough information on these things. Also, how do you index a field in code?
0
1965
by: bcox | last post by:
I would like to be able to set parameter values for an ActiveX control hosted on an ASP.NET .aspx page from a C# code behind file. The ActiveX registration code is contained in <OBJECT></OBJECT> tags hosted in the .aspx file. The control in question is a file viewer. I need to be able to set the filename <PARAM NAME="Filename" VALUE="filename.ext"> reference under the <OBJECT></OBJECT> tags dynamically.
12
4910
by: CLEAR-RCIC | last post by:
Hi, I'm having problems setting focus to a textbox on a web user contol on an asp.net web page. The following script works on normal asp.net pages: <script language="javascript"> function cmdButton1_Clicked() { document.all('txtInput1').focus(); return false; }
8
2267
by: David Lozzi | last post by:
Howdy, I have a user control that is a report to display data. On the page the control is inserted in, I have filter options to filter the report. When I try to do something like this, nothing happens. dim filt as string ... build filter string... UserControl.ReportFilter = filt
3
1017
by: Dave | last post by:
If I have a name of a User Control in my project, how can I set an Object to that User Control? ie; I have a User Control, called "Accounts" in my project I tried the following code strUserControlName = "Accounts" frmMain.Controls.Add(strUserControlName)
6
11083
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
6
10127
by: alun65 | last post by:
I'm having trouble programmatically adding a user control and then setting some of it's server controls. I add the user control to the code behind and add it to a placeholder: protected void Page_Load(object sender, EventArgs e) { UserControls_WebUserControl myControl = new UserControls_WebUserControl(); PlaceHolder1.Controls.Add(web);
0
9688
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10247
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9079
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7571
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6809
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4146
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 we have to send another system
2
3762
muto222
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.