473,671 Members | 2,480 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 2608
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
7568
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
2668
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
1158
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
2845
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
3938
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
1561
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
1690
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
1911
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
8401
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,...
0
8926
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8824
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8603
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
8673
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
6236
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
4227
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...
0
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2060
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.