473,508 Members | 2,374 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding controls programmatically.

Hi,

This is what I am doing, please comment if this is the correct way.

I need to add controls to a form dynamically.
Within the Page_Load event (is not Postback) I run a routine to create the
controls, and populate the dropdowns etc,
I use addhandler to define delegates to capture events raised by the
controls.
I store these controls in a hashtable.
I store the hashtables in the session store. (??)
Then also within the Page_Load event (run each time), I repopulate the hash
tables from the session store. I then run a routine to add the controls to
and existing table on the form. (this bit is run every the page is posted as
the controls disappear from the table)

All seems OK so far.

When the form is run, the events fire OK.

However, if I place code within the event to amend properties of design time
controls on the form, the changes are not reflected upon the form when it is
next displayed. Run the same code in a design time control event and all is
OK.

It seems I can amend properties of other dynamic controls but not design
time controls.

Please comment on my methods, and offer advise.

Secondly.

I have placed a data set on the form, and populate this once in the page
load. If I reference the dataset in the dynamic control events it is
populated, if I reference it in the design time control events it is empty.
?????

There seems to be 2 environments, one for design time controls and one for
dynamic controls. I am confused!!

Tim.

I am new to ASP.NET please see my other posts on the subject.


Nov 18 '05 #1
2 2087
Hi Tim,

As for the dynamic created web server controls, here are some of my
suggestions:

Yes, you're right the dynamically created control should be added into the
page's control hierarchy everytime the page is loaded , not just once ,
also if we add event handler for it, the handler also need to be registered
everytime before the page's event processing occur so that we can make sure
the event handler will be called.

As for your situation, you do some changes on the designtime added controls
in the dynamic control's eventhandler, I think the problem is that you
haven't added the event handler for the dynamic control everytime,(no
matter you first time created or retrieve from Session). Thus, you found
that the event will fire only the first time:)
In fact, the eventhandler info won't be stored in viewstate and even those
design-time control, their event handler also need to be wiredup everytime
the page loaded( you can find them in the InitializeComponent() method
which is called in page's OnInit event).

So , please try adding the eventhandler everytime the page is load and
retest to see whether this helps. Thanks.
Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx



Nov 18 '05 #2
Hi Tim,

Have you had a chance to check out the suggestions in my last reply or have
you got any further ideas on this issue? If you have anything unclear or if
there're anything else we can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3

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

Similar topics

2
42553
by: Big D | last post by:
Hi all, I'm having a problem adding controls to a panel dynamically. I have a usercontrol that I create and try to add 5 times to the panel, but I only ever see the first control. I know it's...
3
4856
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that...
5
1511
by: Neo Geshel | last post by:
Greetings. I am in a very big pickle. I am trying to add page content - as well as a submit button - programatically to a web form that is supposed to submit to DB and then refresh. That...
9
2752
by: Neo Geshel | last post by:
I have strip-mined, strip-searched, and completely exhausted the Internet (up to the 30th page on Google, with 100 results per page!!), all without finding an answer to my question AS TO WHY IT...
0
1212
by: mark.norgate | last post by:
Righto, a problem with programmatically created controls. Well, in that kind of area anyway. I'm creating and adding controls to my page using TemplateControl.LoadControl quite successfully, but...
2
1324
by: johnb41 | last post by:
I want to create a textbox programmatically and add the SAME textbox to to different panels. This code does not work: Dim tb As New TextBox tb.text = "xyz" Panel1.Controls.Add(tb)...
6
11058
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
2
15043
by: ChrisCicc | last post by:
Hi All, I got a real doozy here. I have read hundreds upon hundreds of forum posts and found numerous others who have replicated this problem, but have yet to find a solution. Through testing I have...
4
4087
by: alun65 | last post by:
I'm attempting to programmatically build up some HTML in the code behind. Like so: // Create Hyperlink HyperLink link = new HyperLink(); link.NavigateUrl = "nice cat"; link.Text = "Cats...
6
10098
by: alun65 | last post by:
I'm having trouble programmatically adding a user control and then setting some of it's server controls. I add the user control to the code behind and add it to a placeholder: protected void...
0
7120
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...
0
7380
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...
0
7494
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...
0
5626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5050
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...
0
3192
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1553
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 ...
0
415
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...

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.