Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Building Controls > Composite Web Control and saving user changes on child controls.

Reply
Thread Tools

Composite Web Control and saving user changes on child controls.

 
 
Buzz
Guest
Posts: n/a
 
      12-23-2005
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
 
Reply With Quote
 
 
 
 
Kevin Yu [MSFT]
Guest
Posts: n/a
 
      12-24-2005
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."

 
Reply With Quote
 
 
 
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      12-26-2005
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==?=" <>
| 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->
| 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
|

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      12-28-2005
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->
| 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.buildingc ontrols
| Message-ID: <#>
| 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==?=" <>
| | 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->
| | 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
| |
|
|

 
Reply With Quote
 
Buzz
Guest
Posts: n/a
 
      01-11-2006
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->
> | 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.buildingc ontrols
> | Message-ID: <#>
> | 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==?=" <>
> | | 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->
> | | 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
> | |
> |
> |
>
>

 
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
persisting changes to a control outside a user control from the user control? Mad Scientist Jr ASP .Net 0 03-22-2006 08:02 AM
Losing Composite Control property that another Composite Control ... Chad ASP .Net Building Controls 0 02-01-2005 09:01 PM
Possible to create a composite control that has a child control that is a validator that validates the composite control itself? Jonathan Eric Miller ASP .Net Building Controls 2 07-22-2004 10:58 PM
How do I: Main thread spawn child threads, which child processes...control those child processes? Jeff Rodriguez C Programming 23 12-09-2003 11:06 PM
Custom Composite Control, child User-controls loosing view state Mike J. ASP .Net Building Controls 1 11-24-2003 09:48 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57