473,378 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Problem creating web user control

Hi all,

I have a problem in creating web user control *programatically*. Problem as
follows:

1. WebUserControl1 contains a server side table named Table1
2. WebForm1 contain a server panel and server form.
3. In WebForm1.aspx.cs, I created a WebUserControl1 and attached it to panel
by:
WebUserControl1 oCtl = new WebUserControl1();
panel.Controls.Add(oCtl);
4. I have put a message in WebUserControl1::Page_Load() to display the
validity (null or not null) of the server side table Table1
5. When I load the WebForm1, the Page_Load of WebUSerControl1 was loaded
twice (first problem), and both of them shows that the Table1 is null!
(problem 2)

Any one pls help...I am hopeless here. Thanks.

Calvin


Nov 18 '05 #1
3 1509
The correct syntax for adding a User Control programmatically to a Page or
Control would be to use the Page.LoadControl() method. Example:

WebUserControl1 oCtl = LoadControl("WebUserControl1.ascx");
panelID.Controls.Add(oCtl);

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Calvin Lai" <ca********@i010.com> wrote in message news:9_vEb.
10*************@twister01.bloor.is.net.cable.roger s.com...
Hi all,

I have a problem in creating web user control *programatically*. Problem as follows:

1. WebUserControl1 contains a server side table named Table1
2. WebForm1 contain a server panel and server form.
3. In WebForm1.aspx.cs, I created a WebUserControl1 and attached it to panel by:
WebUserControl1 oCtl = new WebUserControl1();
panel.Controls.Add(oCtl);
4. I have put a message in WebUserControl1::Page_Load() to display the
validity (null or not null) of the server side table Table1
5. When I load the WebForm1, the Page_Load of WebUSerControl1 was loaded
twice (first problem), and both of them shows that the Table1 is null!
(problem 2)

Any one pls help...I am hopeless here. Thanks.

Calvin

Nov 18 '05 #2
Hi,
It there any difference in the process of creation between the two? (new Vs
LoadControl). Thanks for your help.

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:#L**************@TK2MSFTNGP11.phx.gbl...
The correct syntax for adding a User Control programmatically to a Page or
Control would be to use the Page.LoadControl() method. Example:

WebUserControl1 oCtl = LoadControl("WebUserControl1.ascx");
panelID.Controls.Add(oCtl);

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Calvin Lai" <ca********@i010.com> wrote in message news:9_vEb.
10*************@twister01.bloor.is.net.cable.roger s.com...
Hi all,

I have a problem in creating web user control *programatically*. Problem

as
follows:

1. WebUserControl1 contains a server side table named Table1
2. WebForm1 contain a server panel and server form.
3. In WebForm1.aspx.cs, I created a WebUserControl1 and attached it to

panel
by:
WebUserControl1 oCtl = new WebUserControl1();
panel.Controls.Add(oCtl);
4. I have put a message in WebUserControl1::Page_Load() to display the
validity (null or not null) of the server side table Table1
5. When I load the WebForm1, the Page_Load of WebUSerControl1 was loaded
twice (first problem), and both of them shows that the Table1 is null!
(problem 2)

Any one pls help...I am hopeless here. Thanks.

Calvin


Nov 18 '05 #3
> It there any difference in the process of creation between the two? (new
Vs
LoadControl). Thanks for your help.
....besides the fact that one method works and the other doesn't? ;-)

I'm not sure offhand, although I'm sure if I spent some time researching it
I'm sure I could find out. I suspect it is because the User Control, like
the Page class, is a Templated Control. When you call New on the class, you
don't get the Template, just the CodeBehind class. Calling LoadControl()
instantiates the Template which inherits the CodeBehind.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.

"Calvin Lai" <ca********@i010.com> wrote in message
news:2a********************@news04.bloor.is.net.ca ble.rogers.com... Hi,
It there any difference in the process of creation between the two? (new Vs LoadControl). Thanks for your help.

"Kevin Spencer" <ke***@takempis.com> wrote in message
news:#L**************@TK2MSFTNGP11.phx.gbl...
The correct syntax for adding a User Control programmatically to a Page or Control would be to use the Page.LoadControl() method. Example:

WebUserControl1 oCtl = LoadControl("WebUserControl1.ascx");
panelID.Controls.Add(oCtl);

--
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
"Calvin Lai" <ca********@i010.com> wrote in message news:9_vEb.
10*************@twister01.bloor.is.net.cable.roger s.com...
Hi all,

I have a problem in creating web user control *programatically*. Problem
as
follows:

1. WebUserControl1 contains a server side table named Table1
2. WebForm1 contain a server panel and server form.
3. In WebForm1.aspx.cs, I created a WebUserControl1 and attached it to

panel
by:
WebUserControl1 oCtl = new WebUserControl1();
panel.Controls.Add(oCtl);
4. I have put a message in WebUserControl1::Page_Load() to display the
validity (null or not null) of the server side table Table1
5. When I load the WebForm1, the Page_Load of WebUSerControl1 was

loaded twice (first problem), and both of them shows that the Table1 is null!
(problem 2)

Any one pls help...I am hopeless here. Thanks.

Calvin



Nov 18 '05 #4

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

Similar topics

1
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the...
6
by: Robin Bonin | last post by:
In my user contol I am creating a set of dropdownlists. Each list is created based on input from the other lists. The problem I am having is setting the selected index on the lists. If someone...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am have facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the...
1
by: Kamal Jeet Singh | last post by:
Hi Friends !! I am facing problem in controlling the dynamically created controls on web page. The problem Scenario is Scenario:- My requirement is to load the web user controls on the web...
9
by: Anders K. Jacobsen [DK] | last post by:
Hi I have this that adds some usercontrol (UCTodays.ascx) to a placeholder foreach(A a in B){ UCTodays ucline = (UCTodays )LoadControl("UCTodays.ascx");...
10
by: Charles Law | last post by:
For some reason, when I click the X to close my MDI parent form, the action appears to be re-directed to one of the MDI child forms, and the parent remains open. I am then unable to close the...
13
by: Lee Newson | last post by:
Hi, I have just written my first application using VB.NET. The app works fine when i am running it within .NET for debugging purposes, however when i try to run the app from the .exe file that...
7
by: Dino Buljubasic | last post by:
Hi, I am using C# 2.0 (VS2005) to build my user control that contains a number of dynamically loaded ListViews. ListViewItems have their ForeColor properties set to either black or blue to...
14
by: =?Utf-8?B?UHVjY2E=?= | last post by:
Hi, I'm using VS2005 and .net 2.0. I'm creating an application that has 3 forms. I want allow users to move forward and backward with the forms and retain the data users have entered. I thought...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.