Custom Control Question.. 
Author Message
 Custom Control Question..

As I work my way through the C# / .NET topics, this week I've been
concentrating on custom controls.  I came accross the following code that
does not seem to work. I've been through a number of sources to see if I
missed anything but with no luck.. Any help would be appreciated.

1. The first custom control is derived from Button. And works great.. as
expected ( for what is does).

 [ToolboxData("<{0}:SingleControl runat=server></{0}:SingleControl>")]
 public class SingleControl : System.Web.UI.WebControls.Button
 {
  public SingleControl()
  {
   this.Width = 100;
   this.Height = 100;
   this.Click += new System.EventHandler(this.MyOnClick);
   this.Text = "A";
   this.Font.Bold = true;
   this.Font.Size = 50;
  }

  private void MyOnClick( object sender, System.EventArgs e)
  {
   if( Text == "A" )
    Text = "B";
   else
    Text = "A";
  }
 }

2. Using CreateChildControls, I create an instance of this control within
the control WebControl. On the WebForm, I have one instance of the
SingleControl and one instance of the MultipleControls. The control displays
as expected BUT when you click on the MultipleControl, the SingleControl
changes from A to B ( and back again). The MultipleControls NEVER changes. I
suspect it is something I do not know...

The C# code is below.

 [ToolboxData("<{0}:MultipleControls runat=server></{0}:MultipleControls>")]
 public class MultipleControls : System.Web.UI.WebControls.WebControl
 {
  protected override void CreateChildControls()
  {
   SingleControl s = new SingleControl();
   Controls.Add( s );
  }
 }

and the Webform HTML code is..


Assembly="ControlBugParts" %>

Inherits="ControlBug.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
<meta content="Microsoft Visual Studio 7.0" name=GENERATOR>
<meta content=C# name=CODE_LANGUAGE>
<meta content="JavaScript (ECMAScript)" name=vs_defaultClientScript>
<meta content= http://www.*-*-*.com/
name=vs_targetSchema>
  </HEAD>
<body MS_POSITIONING="GridLayout">
<form id=Form1 method=post runat="server">
<cc1:singlecontrol id=SingleControl1 style="Z-INDEX: 101; LEFT: 10px;
POSITION: absolute; TOP: 177px" runat="server" Width="141px"
Height="96px"></cc1:singlecontrol>
<cc1:multiplecontrols id=MultipleControls1 style="Z-INDEX: 102; LEFT: 15px;
POSITION: absolute; TOP: 14px" runat="server" Width="122px"
Height="103px"></cc1:multiplecontrols></FORM>

  </body>
</HTML>

Any thoughts welcome! Thanks...



Tue, 02 Mar 2004 05:58:41 GMT  
 
 [ 1 post ] 

 Relevant Pages 

1. Custom Control question

2. Proper Group for Custom Control Questions?

3. Custom Control question

4. Custom control question

5. HOWTO : Design-time custom collection editing for custom control

6. ASP.NET user control custom designer question

7. ASP.NET user control custom designer question

8. Some last question about custom controls

9. Question about Custom Control resources

10. Question on creating custom controls?

11. Question: How to use a custom control?

12. "Custom" Derived Control Question

 

 
Powered by phpBB® Forum Software