![]() |
Composite Web Control and saving user changes on child controls.
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 |
RE: Composite Web Control and saving user changes on child controls.
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." |
RE: Composite Web Control and saving user changes on child controls.
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...webuiinamingco 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==?=" <buzz@online.nospam> | Subject: Composite Web Control and saving user changes on child controls. | Date: Fri, 23 Dec 2005 12:53:02 -0800 | Lines: 71 | Message-ID: <27167CBE-C197-494B-8AA7-E55A17AFA0E8@microsoft.com> | 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.buildingc ontrols | 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.buildingc ontrols:14162 | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols | | 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 | |
RE: Composite Web Control and saving user changes on child controls.
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: <27167CBE-C197-494B-8AA7-E55A17AFA0E8@microsoft.com> | MIME-Version: 1.0 | Content-Type: text/plain | Content-Transfer-Encoding: 7bit | From: stcheng@online.microsoft.com (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.buildingc ontrols | Message-ID: <#YgpcefCGHA.2636@TK2MSFTNGXA02.phx.gbl> | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols | Lines: 128 | Path: TK2MSFTNGXA02.phx.gbl | Xref: TK2MSFTNGXA02.phx.gbl microsoft.public.dotnet.framework.aspnet.buildingc ontrols: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...webuiinamingco | 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==?=" <buzz@online.nospam> | | Subject: Composite Web Control and saving user changes on child controls. | | Date: Fri, 23 Dec 2005 12:53:02 -0800 | | Lines: 71 | | Message-ID: <27167CBE-C197-494B-8AA7-E55A17AFA0E8@microsoft.com> | | 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.buildingc ontrols | | 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.buildingc ontrols:14162 | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols | | | | 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 | | | | |
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: <27167CBE-C197-494B-8AA7-E55A17AFA0E8@microsoft.com> > | MIME-Version: 1.0 > | Content-Type: text/plain > | Content-Transfer-Encoding: 7bit > | From: stcheng@online.microsoft.com (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.buildingc ontrols > | Message-ID: <#YgpcefCGHA.2636@TK2MSFTNGXA02.phx.gbl> > | Newsgroups: microsoft.public.dotnet.framework.aspnet.buildingc ontrols > | Lines: 128 > | Path: TK2MSFTNGXA02.phx.gbl > | Xref: TK2MSFTNGXA02.phx.gbl > microsoft.public.dotnet.framework.aspnet.buildingc ontrols: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...webuiinamingco > | 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==?=" <buzz@online.nospam> > | | Subject: Composite Web Control and saving user changes on child > controls. > | | Date: Fri, 23 Dec 2005 12:53:02 -0800 > | | Lines: 71 > | | Message-ID: <27167CBE-C197-494B-8AA7-E55A17AFA0E8@microsoft.com> > | | 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.buildingc ontrols > | | 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.buildingc ontrols:14162 > | | X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.buildingc ontrols > | | > | | 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 > | | > | > | > > |
| All times are GMT. The time now is 04:23 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.