PC Review


Reply
Thread Tools Rate Thread

ChildControls state

 
 
mauricio
Guest
Posts: n/a
 
      11th Mar 2008
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);
}
}
 
Reply With Quote
 
 
 
 
bruce barker
Guest
Posts: n/a
 
      11th Mar 2008
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)


"mauricio" wrote:

> 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);
> }
> }
>

 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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
State table lookup - How can I display full state name only on data entry? mthornblad@gmail.com Microsoft Access Forms 1 30th Aug 2007 05:29 PM
User Control's childcontrols have wrong size pompair Microsoft Dot NET Framework Forms 0 23rd Oct 2006 11:13 AM
how do I create a form that selects a state & then only show that state's cities bayouplayer Microsoft Access Form Coding 1 28th Apr 2006 03:06 AM
ChildControls and ViewState Graham Microsoft ASP .NET 1 6th Sep 2005 01:19 PM
Asus notebook resumes from standby state to power on state by itself tinke Windows XP General 1 5th Feb 2005 01:17 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:55 PM.