Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Issue with generating webcontrol dynamically...

Reply
Thread Tools

Issue with generating webcontrol dynamically...

 
 
scsharma
Guest
Posts: n/a
 
      02-03-2005
We have 508 compliance issues where every <input> tag should have associated
label. The label have to speicfy the control that it is associated to, in
this case the checkbox. This is done by setting the associatedControlID
property of label.
I am using data grid and i want to have a checkbox as one of the column.
For that i am creating a template class and in InstantiateIn(Control
container) function
i am dynamically creating a check box and adding that check box to control
collection.
Since the checkbox generates <input> tag I would like to have corresponding
label so that
i can set the associatedControlID property of the label to checkbox. But
when final
HTML is generated instead of <label> tag I am seeing <span> tag.
What am i doing wrong? How can i generate the <label> tag. Please help.

Here is the code:

public void InstantiateIn(Control container)
{
CheckBox cbx = new CheckBox();
Label lbl = new Label();
cbx.DataBinding +=new EventHandler(cbx_DataBinding);
lbl.DataBinding+=new EventHandler(lbl_DataBinding);
if (staticText !="")
lbl.AssociatedControlID = cbx.ID;
container.Controls.Add(lbl);
container.Controls.Add(cbx);
}

Thanks
sharmasu
 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      02-04-2005
Hi sharmasu,

Thanks for your posting. Regarding on this issue, I've also found another
former thread of yours in this newsgroup:

titled: Generate <Label> tag for input controls...

I've posted my reply there and I've pasted my reply here for your
convenience, if you have any further questions, please feel free to post
here:

====================================
Hi SCSharma,

Thanks for your posting. From your description, you're developing a certain
DataBound control's Template in which you'll dynamically create a checkbox
and a Label control and assign the checkbox.ID to the Label control's
AssociatedControlID property so as to output 508 compliant <label> , but
you found the output is always <span> rather than the expected <label> yes?

Based on the code snippet you provided,
====================
public void InstantiateIn(Control container)
{
CheckBox cbx = new CheckBox();
Label lbl = new Label();
cbx.DataBinding +=new EventHandler(cbx_DataBinding);
lbl.DataBinding+=new EventHandler(lbl_DataBinding);
if (staticText !="")
lbl.AssociatedControlID = cbx.ID;
container.Controls.Add(lbl);
container.Controls.Add(cbx);
}
====================

I think the problem is likely due to the ID of the cbx , as for a
dynamicaly created control, if we don't explicitly assign ID to it, it
will remain null(undefined) until it is added into a certain control's
Controls collection, (at that time, its "AutoGenerateID" method will be
called). So, in the code you used, when you assign id to the
lbl.AssociatedControlID , the cbx.ID is undefined, so this means the lbl
hasn't been associated with any control. To correct this , we have two
means:

1. Explicitly set the ID property after we construct the dynamic control

2. Access the new constructed control's ID after it has been added into a
certain parent control's Controls collection.

HTH.

Thanks & Regards,

Steven Cheng
Microsoft Online Support

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

Thanks & Regards,

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.)


 
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
Custom webcontrol that references another webcontrol Fabricio ASP .Net Building Controls 0 09-21-2005 02:55 AM
Trapping an Exception ocurring in a Webcontrol at the Page or parent WebControl level. ASP .Net 2 01-31-2005 06:34 PM
WebControl inside of WebControl and attaching events Kasabaarde Sumta ASP .Net Building Controls 0 12-13-2004 09:51 PM
WebControl with non-WebControl property Peter Morris [Air Software Ltd] ASP .Net Web Controls 1 12-07-2004 12:25 PM
Can a webcontrol (webcontrol.dll) have a configuration file? Luis Ramírez. ASP .Net Building Controls 2 07-06-2004 04:35 PM



Advertisments