Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

ChildControls state

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
mauricio - 11 Mar 2008 14:21 GMT
Hi,

Sorry for my english.

I have a custom server control that derive from Panel.

In my control I want to add an Checkbox, but after an postback it
checkbox lost the state of checked property.

My code:

   public class CheckboxPanel : System.Web.UI.WebControls.Panel,
IPostBackDataHandler
   {
       private CheckBox _chk = new CheckBox();

       protected override void CreateChildControls()
       {
           _chk = new CheckBox();
           _chk.ID = this.ClientID + "_chk";
       }

       public override void RenderBeginTag(HtmlTextWriter writer)
       {
           base.RenderBeginTag(writer);

           writer.AddStyleAttribute(HtmlTextWriterStyle.Width,
"100%");

           writer.RenderBeginTag(HtmlTextWriterTag.Table);

           writer.RenderBeginTag(HtmlTextWriterTag.Tr);

           writer.RenderBeginTag(HtmlTextWriterTag.Td);

           _chk.RenderControl(writer);

           writer.RenderEndTag();  // TD

           writer.RenderEndTag();  // TR

           writer.RenderBeginTag(HtmlTextWriterTag.Tr);

           writer.RenderBeginTag(HtmlTextWriterTag.Td);
       }

       public override void RenderEndTag(HtmlTextWriter writer)
       {
           writer.RenderEndTag();
           writer.RenderEndTag();
           writer.RenderEndTag();

           base.RenderEndTag(writer);
       }
   }
bruce barker - 11 Mar 2008 16:23 GMT
the ceckbox you create is private variable, not a child of your control, so
that your code is handling the event cycle for the checkbox. you need to
handle the loadpostbackdata event also if you want postback data loaded. you
can either fire the event, or load the postback yourself.

the other approach is to make the checkbox a real child. create table (or
generic) objects in  CreateChildControls and add to your Controls collection,
then add the checkbox to the proper child.

-- bruce (sqlwork.com)

> Hi,
>
[quoted text clipped - 51 lines]
>         }
>     }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.