473,320 Members | 2,177 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,320 software developers and data experts.

How do I dynamically create user controls?

Thanks for any help...!

My error is:
Object reference not set to an instance of an object.
public int DisplayOrder {
get {
>> return (int) ViewState["DisplayOrder"];

}

Here's the setup:
I have made a user control that displays a persons picture. Its like this:

AccountName
[PICTURE]
< 1 of 3 >

You can click the arrows to navigate pictures. The control is smart - you
assign the AccountName property and it hits the database, maintains state
with ViewState. I can put several of them on one page if I put them there
statically. When I do this dynamically, I get the above error.

Question:
I have made a repeater which takes a dataset that has a list of account
names in it. It creates one instance of my control for each name in the
list. My controls appear and render correctly. However, I get the above
error when you click on my navigation buttons. Part of the problem is each
instance of my user control has the same ID.

#1 - How can I get the repeater to assign a unique id for each control?

#2 - Is it the case that the state information won't be managed for me
because my controls are dynamic?

When I put multiple instances of my control statically on a page, it works
fine. When its in the repeater, it renders fine but then clicking on the
nav buttons to navigate pictures produces the error.

Thank you so much!
Nov 17 '05 #1
1 5627
Thanks for the tip! I read about this on MSDN, google'd some examples and I
was able to get it to work. However, there is a glitch:

Suppose I have 10 instances of my picture control with the navigation
buttons underneath (because each person can have multiple pictures). When I
click those buttons each control updates correctly, however, the page seems
to refresh and scroll to the top. Can I make it so that the page doesn't
refresh but the control repaints itself?

My architecture is to have a .aspx page with a PersonList user control
sitting on it. That control is passed a list of accountnames (arraylist)
and for each name it loads a PersonPicture user control dynamically and adds
it to the page.

Thanks!

"RMD" <rm*@nospam.sorry.com> wrote in message
news:ek**************@TK2MSFTNGP10.phx.gbl...
Check out the Page.LoadControl method.

RMD

"David J. Berman" <Da**********@bose.com> wrote in message
news:Zj************@paloalto-snr1.gtei.net...
Thanks for any help...!

My error is:
Object reference not set to an instance of an object.
public int DisplayOrder {
get {
>>>>> return (int) ViewState["DisplayOrder"];
}

Here's the setup:
I have made a user control that displays a persons picture. Its like this:
AccountName
[PICTURE]
< 1 of 3 >

You can click the arrows to navigate pictures. The control is smart - you assign the AccountName property and it hits the database, maintains state with ViewState. I can put several of them on one page if I put them there statically. When I do this dynamically, I get the above error.

Question:
I have made a repeater which takes a dataset that has a list of account
names in it. It creates one instance of my control for each name in the
list. My controls appear and render correctly. However, I get the above error when you click on my navigation buttons. Part of the problem is

each
instance of my user control has the same ID.

#1 - How can I get the repeater to assign a unique id for each control?

#2 - Is it the case that the state information won't be managed for me
because my controls are dynamic?

When I put multiple instances of my control statically on a page, it

works
fine. When its in the repeater, it renders fine but then clicking on the nav buttons to navigate pictures produces the error.

Thank you so much!


Nov 17 '05 #2

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

Similar topics

3
by: Kiyomi | last post by:
Hello, I create a Table1 dynamically at run time, and at the same time, I would like to create LinkButton controls, also dynamically, and insert them into each line in my Table1. I would...
2
by: macca | last post by:
Hi, I am writing a GUI application. It will have a number of user defined controls( I plan to use/create a user defined control that will output alarm states that the user can also select and...
8
by: Donald Xie | last post by:
Hi, I noticed an interesting effect when working with controls that are dynamically loaded. For instance, on a web form with a PlaceHolder control named ImageHolder, I dynamically add an image...
4
by: Bas Groeneveld | last post by:
I am developing an ASP.NET application part of which consists of a data entry wizard defined by entries in a data table - ie the controls on each page of the wizard are determined by definitions in...
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...
4
by: Harry | last post by:
Hello, I have a page with a RadioButtonList and a PlaceHolder control. The RadioButtonList's AutoPostBack attribute is set to TRUE and its SelectedIndexChanged event loads one of three...
1
by: Reza Nabi | last post by:
Bakground: I have a webform (LoadCtl.aspx) which loads the user control to a placeholder dynamically based on the ctlName querystring passed in the URL. Webform (LoadCtl.aspx) also passes a...
3
by: Dotnet Gruven | last post by:
I've built a WebForm with a Table added dynamically in Page_Load when IsPostBack is false. The table includes a couple of TextBoxes, RadioButtonLists and CheckboxLists. On postback, those...
2
by: A.Wussow | last post by:
Hi Everybody, i want to load dynamically content from some user controls (with forms, or some data-controls) using atlas. So i use an UpdatePanel for loading the user control into a placeholder....
9
by: netasp | last post by:
hi all, how can I populate one aspx form when page is loading based on page ID? for example: loading page A (to search for VB code) would display labels and texboxes, dropdown lists all related...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.