hi,
I create a UserControl called "RegInfo.ascx",
then i add a PlaceHolder to WebForm1,
and in WebForm1.Page_Load() i wrote the follow statement:
placeHolder.Controls.Add(new RegInfo());
but when i pressed F5 to run the web app, it shows nothing. :(
after search web to find out solution, i replaced upper statement with:
placeHolder.Controls.Add(Page.LoadControl("RegInfo .ascx"));
it work as my expect!
I am so confused about the two results,
Don't they add a new instance of RegInfo into the placeHolder?
Why one can work exactly while anthor don't? 5 1732
When you load a control, you do more than instantiate it..
new RegInfo();, as you know, creates a new instance of a class.
Page.LoadControl also creates a new instance, but also does a lot
more...such as bringing the control up to the same event life cycle. AS you
can imagine, if new did this, it would be inconsitent with how new works for
normal classes (simply calling the constructor...).
Cheers,
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/ - New and Improved (yes, the popup is annoying) http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"alecyy" <ci*******@163.com> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl... hi,
I create a UserControl called "RegInfo.ascx", then i add a PlaceHolder to WebForm1, and in WebForm1.Page_Load() i wrote the follow statement: placeHolder.Controls.Add(new RegInfo()); but when i pressed F5 to run the web app, it shows nothing. :(
after search web to find out solution, i replaced upper statement with: placeHolder.Controls.Add(Page.LoadControl("RegInfo .ascx")); it work as my expect!
I am so confused about the two results, Don't they add a new instance of RegInfo into the placeHolder? Why one can work exactly while anthor don't?
when you do new RegInfo() you are only creating an instance of the code
behind of your user control, which normally doesn't have any code to create
the controls it contains (these are usually on the aspx page that get
compiled). Page.LoadControl("RegInfo.ascx") creates an instance of the
actual user control (which inhertis from the code behind).
-- bruce (sqlwork.com)
"alecyy" <ci*******@163.com> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl... hi,
I create a UserControl called "RegInfo.ascx", then i add a PlaceHolder to WebForm1, and in WebForm1.Page_Load() i wrote the follow statement: placeHolder.Controls.Add(new RegInfo()); but when i pressed F5 to run the web app, it shows nothing. :(
after search web to find out solution, i replaced upper statement with: placeHolder.Controls.Add(Page.LoadControl("RegInfo .ascx")); it work as my expect!
I am so confused about the two results, Don't they add a new instance of RegInfo into the placeHolder? Why one can work exactly while anthor don't?
when you do new RegInfo() you are only creating an instance of the code
behind of your user control, which normally doesn't have any code to create
the controls it contains (these are usually on the aspx page that get
compiled). Page.LoadControl("RegInfo.ascx") creates an instance of the
actual user control (which inhertis from the code behind).
-- bruce (sqlwork.com)
"alecyy" <ci*******@163.com> wrote in message
news:OX**************@TK2MSFTNGP15.phx.gbl... hi,
I create a UserControl called "RegInfo.ascx", then i add a PlaceHolder to WebForm1, and in WebForm1.Page_Load() i wrote the follow statement: placeHolder.Controls.Add(new RegInfo()); but when i pressed F5 to run the web app, it shows nothing. :(
after search web to find out solution, i replaced upper statement with: placeHolder.Controls.Add(Page.LoadControl("RegInfo .ascx")); it work as my expect!
I am so confused about the two results, Don't they add a new instance of RegInfo into the placeHolder? Why one can work exactly while anthor don't?
thx.
i got it.
"Bruce Barker" <br******************@safeco.com> дÈëÏûÏ¢
news:#Z*************@TK2MSFTNGP12.phx.gbl... when you do new RegInfo() you are only creating an instance of the code behind of your user control, which normally doesn't have any code to
create the controls it contains (these are usually on the aspx page that get compiled). Page.LoadControl("RegInfo.ascx") creates an instance of the actual user control (which inhertis from the code behind).
-- bruce (sqlwork.com)
"alecyy" <ci*******@163.com> wrote in message news:OX**************@TK2MSFTNGP15.phx.gbl... hi,
I create a UserControl called "RegInfo.ascx", then i add a PlaceHolder to WebForm1, and in WebForm1.Page_Load() i wrote the follow statement: placeHolder.Controls.Add(new RegInfo()); but when i pressed F5 to run the web app, it shows nothing. :(
after search web to find out solution, i replaced upper statement with: placeHolder.Controls.Add(Page.LoadControl("RegInfo .ascx")); it work as my expect!
I am so confused about the two results, Don't they add a new instance of RegInfo into the placeHolder? Why one can work exactly while anthor don't?
thx.
i got it.
"Bruce Barker" <br******************@safeco.com> дÈëÏûÏ¢
news:#Z*************@TK2MSFTNGP12.phx.gbl... when you do new RegInfo() you are only creating an instance of the code behind of your user control, which normally doesn't have any code to
create the controls it contains (these are usually on the aspx page that get compiled). Page.LoadControl("RegInfo.ascx") creates an instance of the actual user control (which inhertis from the code behind).
-- bruce (sqlwork.com)
"alecyy" <ci*******@163.com> wrote in message news:OX**************@TK2MSFTNGP15.phx.gbl... hi,
I create a UserControl called "RegInfo.ascx", then i add a PlaceHolder to WebForm1, and in WebForm1.Page_Load() i wrote the follow statement: placeHolder.Controls.Add(new RegInfo()); but when i pressed F5 to run the web app, it shows nothing. :(
after search web to find out solution, i replaced upper statement with: placeHolder.Controls.Add(Page.LoadControl("RegInfo .ascx")); it work as my expect!
I am so confused about the two results, Don't they add a new instance of RegInfo into the placeHolder? Why one can work exactly while anthor don't?
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Tom |
last post by:
Hi,
I have an index.aspx page which includes top.aspx,
left.aspx, main.aspx and bottom.aspx.
In the left.aspx, there is a login web control -
login.ascx. It keeps session of username and role...
|
by: martin |
last post by:
Hi,
I am a web page and a web user control. My web user control is placed in my
web page using the following directive
<%@ Register TagPrefix="uc1" TagName="Header"...
|
by: Christopher |
last post by:
I am trying to load a UserControl which inherits from one of our customer
classes which in turn inherits from UserControl. We use Page.LoadControl()
from within our ASP.NET pages to load these...
|
by: Support |
last post by:
Hello:
I have a aspx web page - let's call it main.aspx
It contains a placeholder: Myplaceholder.
I have a web control, lets call it webcontrol which has a code behind class
called...
|
by: Jay Douglas |
last post by:
I have a set of pages that inherit from a base class in the App_Code folder.
The class looks something like:
public class MyBaseClass : System.Web.UI.Page
In various stages of the life cycle I...
|
by: Joe |
last post by:
Hello All,
I have a class that inherits from System.Web.UI.Page. In it I call the
Page.LoadControl. I am having trouble with the virtual path that the
LoadControl method accepts as its...
|
by: RSH |
last post by:
Hi,
I have a situation where I have a user Control (ResultHeader.ascx) that has
a button. I am placing that control into a page (samplePage.aspx). I have
setup a custom event, that should from...
|
by: pyrusmagnus |
last post by:
Hi,
I'm having trouble loading a user control from inside my Sharepoint
webpart. A System.IO.FileNotFoundException occurs on this line:
Control myControl = Page.LoadControl("/UserControls/...
|
by: =?Utf-8?B?SlQtQVJM?= |
last post by:
I have a pretty tricky problem. I have a dynamically built page. I use
Page.ParseControls to parse the "entire page" (ASPX file contains only a Page
tag). ParseControls is pretty resource...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
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...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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...
|
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...
|
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: 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,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
| |