473,672 Members | 2,568 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP.NET 2.0 Dynamic CheckBox example?


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 control creation
and ViewState rehydration, and also let the checkbox click() event
participate properly.

Thanks.

May 24 '07 #1
5 3021

"lucius" <lu****@newsgro up.nospamwrote in message
news:fq******** *************** *********@4ax.c om...
>
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 control creation
and ViewState rehydration, and also let the checkbox click() event
participate properly.
something like this

CheckBox cb = new CheckBox();
cb.Text = "Select";
cb.AutoPostBack = true;
cb.CheckedChang ed +=new EventHandler(cb Changed);
Controls.Add(cb );

public void cbChanged(objec t sender, EventArgs e)
{
CheckBox cb= (CheckBox) sender;
Response.Write( cb.Checked)
}
May 24 '07 #2
Thanks, but in which event is the control created? And will multiple
checkboxes get recreated on each page touch? And will ViewState get
rehydrated properly? And will the dynamic checkbox have access to
Session?

Thanks.

On Thu, 24 May 2007 14:43:43 +0200, "Alexey Smirnov"
<al************ @gmail.comwrote :
>
"lucius" <lu****@newsgro up.nospamwrote in message
news:fq******* *************** **********@4ax. com...
>>
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 control creation
and ViewState rehydration, and also let the checkbox click() event
participate properly.

something like this

CheckBox cb = new CheckBox();
cb.Text = "Select";
cb.AutoPostBac k = true;
cb.CheckedChan ged +=new EventHandler(cb Changed);
Controls.Add(c b);

public void cbChanged(objec t sender, EventArgs e)
{
CheckBox cb= (CheckBox) sender;
Response.Write (cb.Checked)
}
May 24 '07 #3
Hi lucius,

For dynamically created controls in ASP.NET web page, the creation and
event handler wireup should be performed in either Load or Init event(also
could be PreInit or other pre... in ASP.NET 2.0). "Init" is preferred since
LoadViewState occurs after "Init" event and before "Load" event.

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

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

=============== =============== =============== =====

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.

=============== =============== =============== =====

This posting is provided "AS IS" with no warranties, and confers no rights.

May 25 '07 #4
Hi Lucius,

Have you got any progress on this? If there is still anything we can help,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

May 30 '07 #5

Please consider the issue closed.

thanks.
On Wed, 30 May 2007 01:13:44 GMT, st*****@online. microsoft.com (Steven
Cheng[MSFT]) wrote:
>Hi Lucius,

Have you got any progress on this? If there is still anything we can help,
please feel free to post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 6 '07 #6

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

Similar topics

3
13214
by: jason | last post by:
How does one loop through the contents of a form complicated by dynamic construction of checkboxes which are assigned a 'model' and 'listingID' to the NAME field on the fly in this syntax: Hunter_69. Here is what the form looks like. I have the difficulty of inserting the multiple items selected by the user the first time he visits and uses the screen and then using an UPDATE when he visits later. Model | Original Price | Reduced Price...
4
7290
by: Steph | last post by:
Hello, Can someone tell me the script to use for having a change on the same page when using checkbox function ? For example, i would to check one condition and display dynamically a button if the condition is checked on the same page. Thanks in advance for your help
4
2136
by: pizzy | last post by:
INTRO: I tried to clean it up for easy reading. I hope I didn't make any mistakes. PROBLEM: WOW, this is some crazy sh!t. I can't get my checkbox (see "TAGSELECTED") to print my textboxes (see "TAG#") when more than 1 number (see "VLANS") is inputed into my form. QUESTION: How do I make my dynamic form have a dynamic input box(which is created by checking the checkbox and calling the functionC1) inside it and still be able to pass the...
3
1759
by: Chris Thunell | last post by:
I have an aspx web form with a table that i'm sending via response.write... in one of the cells i would like to put a dynamically created server control. The amount of rows is variable... so i could have 10 rows / controls. How do i create a server control that goes into the appropriate grid cell? Example: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
3
3973
by: Leo J. Hart IV | last post by:
OK, here's another question for the experts: I am building a multi-step (3 steps actually) form using a panel for each step and hiding/displaying the appropriate panel/panels depending on which step you're on. This all works fine, but I ran into some trouble when I started creating controls dynamically in my code-behind file. Each panel contains a table which is filled with various radio buttons, text fields and the such which are...
5
4020
by: Irfan Akram | last post by:
Hi Mr.Steve, First of all many thanks for your kind response. The thing is that I am trying to control the user's action of deselecting a checkbox, once he has selected it. Also the checkbox has been generated dynamically. If it is selected I do some other processing, so if it is then deselected then the whole page has to be resetted, hence the sense of displaying the warning message. The problem is that I dont want the warning message...
12
1485
by: scottrm | last post by:
Is there a way to generate a list of say textbox controls dynamically at run time, based on say a value coming out of a database which could vary each time the code is run. In traditional asp you could just have run a loop to do something like that. I am aware in you can use something like Form1.Controls.Add(TextBox1) to add textboxes dynamically at run time but you still need to declare each individual textbox control as far as I can...
34
3790
by: clinttoris | last post by:
Hello Experts, I have been told to post this in the Javascript forum as I want to do this client side just before my form gets submitted. Once the user clicks the submit button a javascript function needs to run and validate all the checkboxes on my form and make sure none of them are unchecked. I suck at Javascript and my problem is 2fold. I have the following code that constructs the checkbox response.write "<input type=checkbox...
1
6013
by: iderocks | last post by:
Hi All, I created a dynamic checkbox in ASP .Net inside a Button1_Click event method (outside the page_load event) and performed the event handling method for the CheckedChanged event and when I check the checkbox at runtime nothing happens (checkBoxObj.check is always false). Does anyone have information on how to make this work? Note: I can get it to work inside Page_Load event. I need help in getting it to work in a different event...
0
8486
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8404
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
8828
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
8680
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
7446
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...
0
5705
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
2819
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
2063
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1816
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.