Composite Web Control and saving user changes on child controls.

Discussion in 'ASP .Net Building Controls' started by Buzz, Dec 23, 2005.

  1. Buzz

    Buzz Guest

    Okay, having the same problem many others are having.

    Here is a simple example I cannot get to work:

    -- using C#

    a) Created an ASP.NET Web Project.

    b) Added a Web Control Library project to the solution calling the project
    CustomControlLibrary.

    c) I've tried a few different things but this is the latest of what my
    WebCustomControl1.cs file looks like this:
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.ComponentModel;

    namespace CustomControlLibrary
    {
    /// <summary>
    /// Summary description for WebCustomControl1.
    /// </summary>
    [DefaultProperty("Text"),
    ToolboxData("<{0}:WebCustomControl1 runat=server></{0}:WebCustomControl1>")]
    public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
    {
    private System.Web.UI.WebControls.CheckBox checkBox;

    /// <summary>
    /// Render this control to the output parameter specified.
    /// </summary>
    /// <param name="output"> The HTML writer to write out to </param>
    protected override void Render(HtmlTextWriter output)
    {
    base.Render(output);
    }


    protected override void CreateChildControls()
    {
    checkBox = new CheckBox();
    Controls.Add(checkBox);
    checkBox.Text = "Confused";

    base.CreateChildControls();
    }

    }
    }

    d) I compiled the solution and then added my CustomControlLibrary to the web
    toolbox.

    e) I dragged and dropped WebCustomControl1 onto WebForm1.aspx.

    f) I also dragged and dropped a textbox and button onto WebForm1.aspx.

    g) I run the solution. I see the checkbox, textbox and button.

    h) I click the checkbox so it is checked, I type "a" in the textbox and then
    I press the button.

    i) The page posts back. I see the "a" in the textbox but the checkbox is now
    unchecked.

    What other code do I need to add to WebCustomControl1.cs so that the
    checkbox remembers the user checked it?

    Thanks,
    Buzz
    Buzz, Dec 23, 2005
    #1
    1. Advertising

  2. Hi Buzz,

    We have reviewed this issue and are currently researching on it. We will
    update you ASAP. Thanks for your patience!

    Kevin Yu
    =======
    "This posting is provided "AS IS" with no warranties, and confers no
    rights."
    Kevin Yu [MSFT], Dec 24, 2005
    #2
    1. Advertising

  3. Hi Buzz,

    As for ASP.NET custom webserver control, if we're developing through the
    composite control means, we need to pay attention to the following things:

    1. Since our custom webserver control will contains multiple sub server
    controls, we need to assign a unique control ID for each of them....
    Thus, we can ensure that the sub controls has a certain ID to idenitify
    them. It is not only important for the runtime service such as ViewState or
    postbacking event mapping but also important for ourselves(we may need to
    use FindControl to reference subcontrols....) So please explicitly assign
    each child control a unique ID value.... (don't let the runtime create a
    random one....) e.g:


    protected override void CreateChildControls()
    {
    CheckBox checkBox = new CheckBox();
    checkBox.ID = "chkSub";
    Controls.Add(checkBox);
    checkBox.Text = "Confused";

    base.CreateChildControls();
    }


    2. For custom composite control , we also need to make it implement the
    INamingContainer interface. This interface dosn't contains any method that
    need to implement but used to indicate that this control is a
    NamingContainer, so all the sub controls in its controls collection will
    have a unique identity over the whole Page scope (thus, the child controls'
    ID in this control won't conflict with those in other controls' child
    control collectoin). e.g:

    public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,
    INamingContainer
    {


    #INamingContainer Interface
    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiinamingco
    ntainerclasstopic.asp?frame=true

    Hope helps. Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)





    --------------------
    | Thread-Topic: Composite Web Control and saving user changes on child
    controls.
    | thread-index: AcYIAt2VNMlq0d4yTBu2rx77O7RIoQ==
    | X-WBNR-Posting-Host: 192.41.148.220
    | From: "=?Utf-8?B?QnV6eg==?=" <>
    | Subject: Composite Web Control and saving user changes on child controls.
    | Date: Fri, 23 Dec 2005 12:53:02 -0800
    | Lines: 71
    | Message-ID: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain;
    | charset="Utf-8"
    | Content-Transfer-Encoding: 7bit
    | X-Newsreader: Microsoft CDO for Windows 2000
    | Content-Class: urn:content-classes:message
    | Importance: normal
    | Priority: normal
    | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:14162
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    |
    | Okay, having the same problem many others are having.
    |
    | Here is a simple example I cannot get to work:
    |
    | -- using C#
    |
    | a) Created an ASP.NET Web Project.
    |
    | b) Added a Web Control Library project to the solution calling the
    project
    | CustomControlLibrary.
    |
    | c) I've tried a few different things but this is the latest of what my
    | WebCustomControl1.cs file looks like this:
    | using System;
    | using System.Web.UI;
    | using System.Web.UI.WebControls;
    | using System.ComponentModel;
    |
    | namespace CustomControlLibrary
    | {
    | /// <summary>
    | /// Summary description for WebCustomControl1.
    | /// </summary>
    | [DefaultProperty("Text"),
    | ToolboxData("<{0}:WebCustomControl1
    runat=server></{0}:WebCustomControl1>")]
    | public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
    | {
    | private System.Web.UI.WebControls.CheckBox checkBox;
    |
    | /// <summary>
    | /// Render this control to the output parameter specified.
    | /// </summary>
    | /// <param name="output"> The HTML writer to write out to </param>
    | protected override void Render(HtmlTextWriter output)
    | {
    | base.Render(output);
    | }
    |
    |
    | protected override void CreateChildControls()
    | {
    | checkBox = new CheckBox();
    | Controls.Add(checkBox);
    | checkBox.Text = "Confused";
    |
    | base.CreateChildControls();
    | }
    |
    | }
    | }
    |
    | d) I compiled the solution and then added my CustomControlLibrary to the
    web
    | toolbox.
    |
    | e) I dragged and dropped WebCustomControl1 onto WebForm1.aspx.
    |
    | f) I also dragged and dropped a textbox and button onto WebForm1.aspx.
    |
    | g) I run the solution. I see the checkbox, textbox and button.
    |
    | h) I click the checkbox so it is checked, I type "a" in the textbox and
    then
    | I press the button.
    |
    | i) The page posts back. I see the "a" in the textbox but the checkbox is
    now
    | unchecked.
    |
    | What other code do I need to add to WebCustomControl1.cs so that the
    | checkbox remembers the user checked it?
    |
    | Thanks,
    | Buzz
    |
    Steven Cheng[MSFT], Dec 26, 2005
    #3
  4. Hi Buzz,

    Does my last reply helps a little? If you have anything unclear or anything
    else we can help, please feel free to post here.

    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.)
    --------------------
    | X-Tomcat-ID: 96655054
    | References: <>
    | MIME-Version: 1.0
    | Content-Type: text/plain
    | Content-Transfer-Encoding: 7bit
    | From: (Steven Cheng[MSFT])
    | Organization: Microsoft
    | Date: Mon, 26 Dec 2005 08:37:19 GMT
    | Subject: RE: Composite Web Control and saving user changes on child
    controls.
    | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | Message-ID: <#>
    | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | Lines: 128
    | Path: TK2MSFTNGXA02.phx.gbl
    | Xref: TK2MSFTNGXA02.phx.gbl
    microsoft.public.dotnet.framework.aspnet.buildingcontrols:14169
    | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
    |
    | Hi Buzz,
    |
    | As for ASP.NET custom webserver control, if we're developing through the
    | composite control means, we need to pay attention to the following things:
    |
    | 1. Since our custom webserver control will contains multiple sub server
    | controls, we need to assign a unique control ID for each of them....
    | Thus, we can ensure that the sub controls has a certain ID to idenitify
    | them. It is not only important for the runtime service such as ViewState
    or
    | postbacking event mapping but also important for ourselves(we may need
    to
    | use FindControl to reference subcontrols....) So please explicitly
    assign
    | each child control a unique ID value.... (don't let the runtime create a
    | random one....) e.g:
    |
    |
    | protected override void CreateChildControls()
    | {
    | CheckBox checkBox = new CheckBox();
    | checkBox.ID = "chkSub";
    | Controls.Add(checkBox);
    | checkBox.Text = "Confused";
    |
    | base.CreateChildControls();
    | }
    |
    |
    | 2. For custom composite control , we also need to make it implement the
    | INamingContainer interface. This interface dosn't contains any method
    that
    | need to implement but used to indicate that this control is a
    | NamingContainer, so all the sub controls in its controls collection will
    | have a unique identity over the whole Page scope (thus, the child
    controls'
    | ID in this control won't conflict with those in other controls' child
    | control collectoin). e.g:
    |
    | public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,
    | INamingContainer
    | {
    |
    |
    | #INamingContainer Interface
    |
    http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiinamingco
    | ntainerclasstopic.asp?frame=true
    |
    | Hope helps. Thanks,
    |
    | Steven Cheng
    | Microsoft Online Support
    |
    | Get Secure! www.microsoft.com/security
    | (This posting is provided "AS IS", with no warranties, and confers no
    | rights.)
    |
    |
    |
    |
    |
    | --------------------
    | | Thread-Topic: Composite Web Control and saving user changes on child
    | controls.
    | | thread-index: AcYIAt2VNMlq0d4yTBu2rx77O7RIoQ==
    | | X-WBNR-Posting-Host: 192.41.148.220
    | | From: "=?Utf-8?B?QnV6eg==?=" <>
    | | Subject: Composite Web Control and saving user changes on child
    controls.
    | | Date: Fri, 23 Dec 2005 12:53:02 -0800
    | | Lines: 71
    | | Message-ID: <>
    | | MIME-Version: 1.0
    | | Content-Type: text/plain;
    | | charset="Utf-8"
    | | Content-Transfer-Encoding: 7bit
    | | X-Newsreader: Microsoft CDO for Windows 2000
    | | Content-Class: urn:content-classes:message
    | | Importance: normal
    | | Priority: normal
    | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    | | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    | | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    | | Xref: TK2MSFTNGXA02.phx.gbl
    | microsoft.public.dotnet.framework.aspnet.buildingcontrols:14162
    | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    | |
    | | Okay, having the same problem many others are having.
    | |
    | | Here is a simple example I cannot get to work:
    | |
    | | -- using C#
    | |
    | | a) Created an ASP.NET Web Project.
    | |
    | | b) Added a Web Control Library project to the solution calling the
    | project
    | | CustomControlLibrary.
    | |
    | | c) I've tried a few different things but this is the latest of what my
    | | WebCustomControl1.cs file looks like this:
    | | using System;
    | | using System.Web.UI;
    | | using System.Web.UI.WebControls;
    | | using System.ComponentModel;
    | |
    | | namespace CustomControlLibrary
    | | {
    | | /// <summary>
    | | /// Summary description for WebCustomControl1.
    | | /// </summary>
    | | [DefaultProperty("Text"),
    | | ToolboxData("<{0}:WebCustomControl1
    | runat=server></{0}:WebCustomControl1>")]
    | | public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
    | | {
    | | private System.Web.UI.WebControls.CheckBox checkBox;
    | |
    | | /// <summary>
    | | /// Render this control to the output parameter specified.
    | | /// </summary>
    | | /// <param name="output"> The HTML writer to write out to </param>
    | | protected override void Render(HtmlTextWriter output)
    | | {
    | | base.Render(output);
    | | }
    | |
    | |
    | | protected override void CreateChildControls()
    | | {
    | | checkBox = new CheckBox();
    | | Controls.Add(checkBox);
    | | checkBox.Text = "Confused";
    | |
    | | base.CreateChildControls();
    | | }
    | |
    | | }
    | | }
    | |
    | | d) I compiled the solution and then added my CustomControlLibrary to
    the
    | web
    | | toolbox.
    | |
    | | e) I dragged and dropped WebCustomControl1 onto WebForm1.aspx.
    | |
    | | f) I also dragged and dropped a textbox and button onto WebForm1.aspx.
    | |
    | | g) I run the solution. I see the checkbox, textbox and button.
    | |
    | | h) I click the checkbox so it is checked, I type "a" in the textbox and
    | then
    | | I press the button.
    | |
    | | i) The page posts back. I see the "a" in the textbox but the checkbox
    is
    | now
    | | unchecked.
    | |
    | | What other code do I need to add to WebCustomControl1.cs so that the
    | | checkbox remembers the user checked it?
    | |
    | | Thanks,
    | | Buzz
    | |
    |
    |
    Steven Cheng[MSFT], Dec 28, 2005
    #4
  5. Buzz

    Buzz Guest

    RE: Composite Web Control and saving user changes on child control

    Sorry for the delayed response. I was on holidays and for some reason I was
    not being notified of your replies.

    Steven, your answer works perfectly. Thank you!

    "Steven Cheng[MSFT]" wrote:

    > Hi Buzz,
    >
    > Does my last reply helps a little? If you have anything unclear or anything
    > else we can help, please feel free to post here.
    >
    > 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.)
    > --------------------
    > | X-Tomcat-ID: 96655054
    > | References: <>
    > | MIME-Version: 1.0
    > | Content-Type: text/plain
    > | Content-Transfer-Encoding: 7bit
    > | From: (Steven Cheng[MSFT])
    > | Organization: Microsoft
    > | Date: Mon, 26 Dec 2005 08:37:19 GMT
    > | Subject: RE: Composite Web Control and saving user changes on child
    > controls.
    > | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    > | Message-ID: <#>
    > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    > | Lines: 128
    > | Path: TK2MSFTNGXA02.phx.gbl
    > | Xref: TK2MSFTNGXA02.phx.gbl
    > microsoft.public.dotnet.framework.aspnet.buildingcontrols:14169
    > | NNTP-Posting-Host: tomcatimport2.phx.gbl 10.201.218.182
    > |
    > | Hi Buzz,
    > |
    > | As for ASP.NET custom webserver control, if we're developing through the
    > | composite control means, we need to pay attention to the following things:
    > |
    > | 1. Since our custom webserver control will contains multiple sub server
    > | controls, we need to assign a unique control ID for each of them....
    > | Thus, we can ensure that the sub controls has a certain ID to idenitify
    > | them. It is not only important for the runtime service such as ViewState
    > or
    > | postbacking event mapping but also important for ourselves(we may need
    > to
    > | use FindControl to reference subcontrols....) So please explicitly
    > assign
    > | each child control a unique ID value.... (don't let the runtime create a
    > | random one....) e.g:
    > |
    > |
    > | protected override void CreateChildControls()
    > | {
    > | CheckBox checkBox = new CheckBox();
    > | checkBox.ID = "chkSub";
    > | Controls.Add(checkBox);
    > | checkBox.Text = "Confused";
    > |
    > | base.CreateChildControls();
    > | }
    > |
    > |
    > | 2. For custom composite control , we also need to make it implement the
    > | INamingContainer interface. This interface dosn't contains any method
    > that
    > | need to implement but used to indicate that this control is a
    > | NamingContainer, so all the sub controls in its controls collection will
    > | have a unique identity over the whole Page scope (thus, the child
    > controls'
    > | ID in this control won't conflict with those in other controls' child
    > | control collectoin). e.g:
    > |
    > | public class WebCustomControl1 : System.Web.UI.WebControls.WebControl,
    > | INamingContainer
    > | {
    > |
    > |
    > | #INamingContainer Interface
    > |
    > http://msdn.microsoft.com/library/en-us/cpref/html/frlrfsystemwebuiinamingco
    > | ntainerclasstopic.asp?frame=true
    > |
    > | Hope helps. Thanks,
    > |
    > | Steven Cheng
    > | Microsoft Online Support
    > |
    > | Get Secure! www.microsoft.com/security
    > | (This posting is provided "AS IS", with no warranties, and confers no
    > | rights.)
    > |
    > |
    > |
    > |
    > |
    > | --------------------
    > | | Thread-Topic: Composite Web Control and saving user changes on child
    > | controls.
    > | | thread-index: AcYIAt2VNMlq0d4yTBu2rx77O7RIoQ==
    > | | X-WBNR-Posting-Host: 192.41.148.220
    > | | From: "=?Utf-8?B?QnV6eg==?=" <>
    > | | Subject: Composite Web Control and saving user changes on child
    > controls.
    > | | Date: Fri, 23 Dec 2005 12:53:02 -0800
    > | | Lines: 71
    > | | Message-ID: <>
    > | | MIME-Version: 1.0
    > | | Content-Type: text/plain;
    > | | charset="Utf-8"
    > | | Content-Transfer-Encoding: 7bit
    > | | X-Newsreader: Microsoft CDO for Windows 2000
    > | | Content-Class: urn:content-classes:message
    > | | Importance: normal
    > | | Priority: normal
    > | | X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
    > | | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    > | | NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
    > | | Path: TK2MSFTNGXA02.phx.gbl!TK2MSFTNGXA03.phx.gbl
    > | | Xref: TK2MSFTNGXA02.phx.gbl
    > | microsoft.public.dotnet.framework.aspnet.buildingcontrols:14162
    > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingcontrols
    > | |
    > | | Okay, having the same problem many others are having.
    > | |
    > | | Here is a simple example I cannot get to work:
    > | |
    > | | -- using C#
    > | |
    > | | a) Created an ASP.NET Web Project.
    > | |
    > | | b) Added a Web Control Library project to the solution calling the
    > | project
    > | | CustomControlLibrary.
    > | |
    > | | c) I've tried a few different things but this is the latest of what my
    > | | WebCustomControl1.cs file looks like this:
    > | | using System;
    > | | using System.Web.UI;
    > | | using System.Web.UI.WebControls;
    > | | using System.ComponentModel;
    > | |
    > | | namespace CustomControlLibrary
    > | | {
    > | | /// <summary>
    > | | /// Summary description for WebCustomControl1.
    > | | /// </summary>
    > | | [DefaultProperty("Text"),
    > | | ToolboxData("<{0}:WebCustomControl1
    > | runat=server></{0}:WebCustomControl1>")]
    > | | public class WebCustomControl1 : System.Web.UI.WebControls.WebControl
    > | | {
    > | | private System.Web.UI.WebControls.CheckBox checkBox;
    > | |
    > | | /// <summary>
    > | | /// Render this control to the output parameter specified.
    > | | /// </summary>
    > | | /// <param name="output"> The HTML writer to write out to </param>
    > | | protected override void Render(HtmlTextWriter output)
    > | | {
    > | | base.Render(output);
    > | | }
    > | |
    > | |
    > | | protected override void CreateChildControls()
    > | | {
    > | | checkBox = new CheckBox();
    > | | Controls.Add(checkBox);
    > | | checkBox.Text = "Confused";
    > | |
    > | | base.CreateChildControls();
    > | | }
    > | |
    > | | }
    > | | }
    > | |
    > | | d) I compiled the solution and then added my CustomControlLibrary to
    > the
    > | web
    > | | toolbox.
    > | |
    > | | e) I dragged and dropped WebCustomControl1 onto WebForm1.aspx.
    > | |
    > | | f) I also dragged and dropped a textbox and button onto WebForm1.aspx.
    > | |
    > | | g) I run the solution. I see the checkbox, textbox and button.
    > | |
    > | | h) I click the checkbox so it is checked, I type "a" in the textbox and
    > | then
    > | | I press the button.
    > | |
    > | | i) The page posts back. I see the "a" in the textbox but the checkbox
    > is
    > | now
    > | | unchecked.
    > | |
    > | | What other code do I need to add to WebCustomControl1.cs so that the
    > | | checkbox remembers the user checked it?
    > | |
    > | | Thanks,
    > | | Buzz
    > | |
    > |
    > |
    >
    >
    Buzz, Jan 11, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. sleigh
    Replies:
    1
    Views:
    2,685
    sleigh
    Feb 12, 2004
  2. Harry
    Replies:
    2
    Views:
    658
    Harry
    Apr 16, 2004
  3. Mike J.
    Replies:
    1
    Views:
    175
    John Saunders
    Nov 24, 2003
  4. Replies:
    0
    Views:
    201
  5. David Boike

    Child controls in Composite Controls not firing events

    David Boike, Aug 7, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    312
    David Boike
    Aug 7, 2003
Loading...

Share This Page