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

Dynamic Control Event Wireup?



In my ASP.NET page code-behind, I have added a textbox like this:

(C#)
System.Web.UI.HtmlControls.HtmlGenericControl div1= new
HtmlGenericControl( "div" );
div1.ID = "divNewTextBox";
TextBox txt1 = new TextBox();
div1.Controls.Add( txt1 );

Now I want to add the TextChanged event to the textbox as early as
possible so on a PostBack the wired-up event can fire. I think I need
to add the div and textbox before Page_Load, because by then ViewState
is already processed, is that correct?
Nov 18 '05 #1
3 2164
adding it in the page_load also works. but recommended is to put the dynamic
creation of controls in init method.

Av.

"localhost" <pr*******@cohort.ces> wrote in message
news:mi********************************@4ax.com...


In my ASP.NET page code-behind, I have added a textbox like this:

(C#)
System.Web.UI.HtmlControls.HtmlGenericControl div1= new
HtmlGenericControl( "div" );
div1.ID = "divNewTextBox";
TextBox txt1 = new TextBox();
div1.Controls.Add( txt1 );

Now I want to add the TextChanged event to the textbox as early as
possible so on a PostBack the wired-up event can fire. I think I need
to add the div and textbox before Page_Load, because by then ViewState
is already processed, is that correct?

Nov 18 '05 #2
Hi Localhost,

I agree with Avnrao's suggestions that both Page_load and the Init event is
ok to add the dynamic created control and wire their event handler( but we
need to add the control and wire event handler for it everytime the page is
loaded ). And as for the time when to wire up the event handler, the Init
or Load is both ok because as long as we wire up the event handler before
the page processing the serverside controls post back events(it is after
the Page_load) the event will be correctly fired and call the handler. For
detailed info on the asp.net page's serverside event life cycle, you may
view the following article:

#The ASP.NET Page Object Model
http://msdn.microsoft.com/library/en...eobjectmodel.a
sp?frame=true

And the following twos are the reference on creating dynamic controls on
asp.net webform:

#Adding Controls to a Web Forms Page Programmatically
http://msdn.microsoft.com/library/en...controlstowebf
ormspageprogrammatically.asp?frame=true

#HOW TO: Dynamically Create Controls in ASP.NET by Using Visual C# .NET
http://support.microsoft.com/?id=317794

Hope also 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 #3

Hi Localhost,

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 #4

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

Similar topics

3
by: Brian | last post by:
I am so happy to have mastered the technique for "Press Tab to insert". I type " += " and up steps Visual Studio to write my event handler for me. This is more fun than Intellisense. But I...
2
by: greg | last post by:
Hi here is what I am doing - building a table dynamically HtmlTableRow objRow = new HtmlTableRow(); tblStuff.Rows.Add(objRow); HtmlTableCell objCellMain1 = new HtmlTableCell();
1
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...
2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
3
by: csgraham74 | last post by:
Hello, Ive been working on an asp.net application in both dreamweaver and visual studio .Net. Ive imported files created in dreamweaver into my VS.Net application. The main problem that i...
3
by: chelsea | last post by:
I am using a GridView control with a ButtonField and receiving 2 row command events for each click of the button. Is there a configuration switch that I can turn that will ensure I only receive...
0
by: Mike | last post by:
Hi. I can't figure out why a button's click event is not firing in a templated control I've created (first time I've tried creating one). Please can someone help? On a point of lesser importance,...
5
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc...
5
by: lucius | last post by:
Can someone provide a sample of how to add a new CheckBox control to an ASP.NET page, dynamically completely in code-behind? I am having a problem understanding which event should handle the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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,...
0
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
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...

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.