Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP.NET 2.0 Dynamic CheckBox example?

Reply
Thread Tools

ASP.NET 2.0 Dynamic CheckBox example?

 
 
lucius
Guest
Posts: n/a
 
      05-24-2007

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.

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      05-24-2007

"lucius" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>
> 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.CheckedChanged +=new EventHandler(cbChanged);
Controls.Add(cb);

public void cbChanged(object sender, EventArgs e)
{
CheckBox cb= (CheckBox) sender;
Response.Write(cb.Checked)
}


 
Reply With Quote
 
 
 
 
lucius
Guest
Posts: n/a
 
      05-24-2007
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"
<(E-Mail Removed)> wrote:

>
>"lucius" <(E-Mail Removed)> wrote in message
>news:(E-Mail Removed).. .
>>
>> 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.CheckedChanged +=new EventHandler(cbChanged);
>Controls.Add(cb);
>
>public void cbChanged(object sender, EventArgs e)
>{
>CheckBox cb= (CheckBox) sender;
>Response.Write(cb.Checked)
>}
>


 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-25-2007
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.

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-30-2007
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.

 
Reply With Quote
 
lucius
Guest
Posts: n/a
 
      06-06-2007

Please consider the issue closed.

thanks.


On Wed, 30 May 2007 01:13:44 GMT, http://www.velocityreviews.com/forums/(E-Mail Removed) (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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
DataGrid and embeded Checkbox..How to find if checkbox clicked =?Utf-8?B?RG90TmV0RGV2?= ASP .Net 1 10-06-2006 04:11 PM
disable checkbox list checkbox Vikram ASP .Net 1 01-25-2006 02:59 PM
Text on Checkbox below the checkbox tshad ASP .Net 0 04-14-2005 11:26 PM
A nested dynamic checkbox inside my dynamic form. pizzy Javascript 5 04-12-2005 02:55 PM
How to have a nested dynamic checkbox inside my dynamic form. pizzy Javascript 0 03-23-2005 03:32 AM



Advertisments