473,834 Members | 2,148 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datalist in User Control and Dynamic Load it.

Hi!:

I encounter this problem when I do some tests:
I have one user control with datalist in it. The ID for
datalist is "dlTest". Then in this control code behind class, I
declare a protected attribute like "DataList dlTest"
Then I create a test asp page to load my control dynamically.
by using "LoadControl("c ontrols\MyTest. ascx")"
The load is fine and work perfectly. But dlTest
in the Page_Load method of my control class is always null.
If I do not use dynamic loading, it works fine. Does anyone
know the reason?

Thanks for any help!

Yan


Nov 18 '05 #1
4 2616
Jos
"Yan Wang" <yw*******@shaw .ca> wrote in message
news:sonHb.8441 87$pl3.465210@p d7tw3no...
Hi!:

I encounter this problem when I do some tests:
I have one user control with datalist in it. The ID for
datalist is "dlTest". Then in this control code behind class, I
declare a protected attribute like "DataList dlTest"
Then I create a test asp page to load my control dynamically.
by using "LoadControl("c ontrols\MyTest. ascx")"
The load is fine and work perfectly. But dlTest
in the Page_Load method of my control class is always null.
If I do not use dynamic loading, it works fine. Does anyone
know the reason?

Don't use just dlTest, but use
CType(FindContr ol("dlTest"),Da taList)

--

Jos
Nov 18 '05 #2
Hi,

Are you loading the control on postback ? if you use IsPostback to
prevent loading the user control on postback remove it. dynamic controls
should be add every time the page load.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #3
Which means dynamic loading can not map ASP ID to the variable in
code-behind class?
But why? Is it a bug of Microsoft or they have good reason to do so?

Thanks!

Yan
"Jos" <jo************ ***@fastmail.fm > wrote in message
news:%2******** ********@TK2MSF TNGP11.phx.gbl. ..
"Yan Wang" <yw*******@shaw .ca> wrote in message
news:sonHb.8441 87$pl3.465210@p d7tw3no...
Hi!:

I encounter this problem when I do some tests:
I have one user control with datalist in it. The ID for
datalist is "dlTest". Then in this control code behind class, I
declare a protected attribute like "DataList dlTest"
Then I create a test asp page to load my control dynamically.
by using "LoadControl("c ontrols\MyTest. ascx")"
The load is fine and work perfectly. But dlTest
in the Page_Load method of my control class is always null.
If I do not use dynamic loading, it works fine. Does anyone
know the reason?

Don't use just dlTest, but use
CType(FindContr ol("dlTest"),Da taList)

--

Jos

Nov 18 '05 #4
No, I load it always. Actually, I put loading code in Handler of OnPageInit.

Thanks!

Yan

"Natty Gur" <na***@dao2com. com> wrote in message
news:%2******** ********@TK2MSF TNGP09.phx.gbl. ..
Hi,

Are you loading the control on postback ? if you use IsPostback to
prevent loading the user control on postback remove it. dynamic controls
should be add every time the page load.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)58-888377
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #5

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

Similar topics

2
527
by: Mark | last post by:
I have a datalist (see code below). Assume that the datalist is populated with 10 records of data. How do I programatically grab all the data in ALL the columns of the selected record? I've been trying to use the FindControl method inside the ItemCommand event of the DataList to get the contents of the Label below, but it appears that the DataBinder code is making it a child control of the lblInstructorEmplidDisplayed control, rather than...
1
7594
by: Shourie | last post by:
I've noticed that none of the child controls events are firing for the first time from the dynamic user control. Here is the event cycle. 1) MainPage_load 2) User control1_Load user clicks a dropdown in UC1 _________________________ 1) MainPage_Load 2) User Control_1 Load
1
2677
by: Scott Schluer | last post by:
Hello, I've got myself a small problem and I'm hoping someone can help. I have a DataList called dlProducts (displays products from a database). Within the <ItemTemplate> container of the DataList, I have a PlaceHolder control called phVariations. During the ItemDataBound event for dlProducts, I dynamically create a few DropDownLists (again, from a database) and .Add the DropDownList to the PlaceHolder control. That all works just...
0
1164
by: Kode | last post by:
I dont know really know if this is a bug or not. In my webform I hav Header( User control DataLis Footer(User Control The Header User Control has a Place Holder to which menu(another user control) is added dynamically based on the user role. (I have 3 menus for each role, and an appropriate menu is loaded based on the user logged in. private void Page_Load(object sender, System.EventArgs e /
10
2862
by: Bharat | last post by:
Hi Folks, Suppose I have two link button on a page (say lnkBtn1 and lnkBtn2). On the click event of the lnkbtn1 I have to add a dynamically created control. And On the click event of the lnkBtn2 I have to add a datalist control. Using this datalist control I should be able to add edit, modify and cancel the items listed in this control. Here is how I designed. I used placeholder to add the controls dynamically to the page on the click...
0
3949
by: Isz | last post by:
PROBLEM: This problem is related to the postback and handling events correctly. BACKGROUND: I have a datalist which acts as a tabbes list with horizontal layout. This datalist is bound to a strogly typed collection I called TabCollection which is a collevtion of items called tab. Each tab is as follows:
0
1570
by: Rick Wez | last post by:
I feel like I'm going to pull out my hair (there's not much left); I've read almost every online post trying to figure this out. So I started over with something VERY simple and it still doesn't work ... here we go. I have a datalist with an embedded user control. My user control outputs a single string. The first time thru, everything works perfectly ... on a postback, the datalist gets it's values correctly, but the user control does...
3
1706
by: Jon Paal | last post by:
how do I load controls to the templates for the DataList control. <asp:datalist id="dl1" runat="server" > <ItemTemplate> " how to load control(s) here ????" </ItemTemplate> </asp:datalist>
0
1919
by: =?Utf-8?B?Y2luZHk=?= | last post by:
I have am dynamically loading a web user control based on the click of a tab strip I load the default control for the first tab in the page load event after checking page is not postback. After that the controls are loaded/unloaded based on the SelectionChanged event for the tab strip and again in Page load because with a dynamic load viewstate has to be reloaded. I have a datalist in the user control and I am trying to create the...
0
9796
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...
1
10544
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
10214
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7754
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
6951
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
5790
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4425
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
3973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3079
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.