473,785 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding controls programmaticall y.

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 2111
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 InitializeCompo nent() 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
42587
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 the first, because a property of the userControl is to display it's name. The code I have is: //Add detatil widgets to the panel CustControls.DetailWidget x;
3
4885
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 the best method? Do you have a sample of how to do this?
5
1551
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 is, a user goes to the web page, which draws the current content out of the db and inserts into a "preview" area as well as the form itself. User makes changes, hits submit button. The page *should* refresh, with the changes saved to the db, and...
9
2781
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 IS IMPOSSIBLE TO PROGRAMMATICALLY ADD A BUTTON TO A DYNAMICALLY CREATED PAGE. Or, to be more precise, why it is impossible to have an onClick sub respond to that button’s Click event. My main page has only one line:
0
1226
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 I have a button on my page that adds another control (it's a row of a table in a timesheet application). Trouble is, of course, CreateChildControls() is called before AddProject(), which is the method that adds another row to the table. I...
2
1348
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) Panel2.Controls.Add(tb) The textbox gets added to Panel2, but not Panel1. How can i get the textbox to go to both panels? I can get it to work by duplicating the
6
11082
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 how those properties are set. I want to be able to do two other things: a) add User control instances to my page, filling in the place of placeholder controls, and b) programmatically setting custom properties on those dynamically spawned...
2
15071
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 been able to find the cause of the problem, and will describe it here first textually and then through a code example. The purpose of what I am trying to do is to create a postback-free web application through the use of ASP.net AJAX UpdatePanels...
4
4123
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 Sleeping"; //Create Image Image img = new Image();
6
10127
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 Page_Load(object sender, EventArgs e) { UserControls_WebUserControl myControl = new UserControls_WebUserControl(); PlaceHolder1.Controls.Add(web);
0
9480
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
10325
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
10148
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...
0
9950
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...
0
8972
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7499
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
6740
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();...
1
4053
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
3646
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.