Problem with composite control

M

Mark Goldin

I am trying to create my first composite control.

Here is the code:

using System;

using System.Collections;

using System.ComponentModel;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace CompositeControls

{

[ToolboxData("<{0}:LabelMaskEdit runat=server></{0}:InteractiveSearchBox>")]

public class LabelMaskEdit : Table, INamingContainer

{

protected Label LabelName = new Label();

protected Infragistics.WebUI.WebDataInput.WebMaskEdit SearchTextBox = new
Infragistics.WebUI.WebDataInput.WebMaskEdit();


}

}

After I complied the control I can add it to Toolbar with no problem but
when I add the control from Toolbar to aspx page I see a box with "Error
creating control ..."

Can someone help, please?
 
V

Victor Garcia Aprea [MVP]

Hi Mark,

If you move the cursor over the error message you should get a tooltip with
a more specific error message, please post that message to help the guessing
game.

Also note that children controls of a composite control should always be
created in an overriden CreateChildControls methods and not when declaring
the fields as you are doing.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
My profile: http://aspnet2.com/mvp.ashx?vga


Mark Goldin said:
I am trying to create my first composite control.

Here is the code:

using System;

using System.Collections;

using System.ComponentModel;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace CompositeControls

{

[ToolboxData("<{0}:LabelMaskEdit
 
M

Mark Goldin

I have this code now:
using System;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

using Infragistics.WebUI.WebDataInput;

namespace WebControlLib

{

/// <summary>

/// Summary description for WebCustomControl1.

/// </summary>

[DefaultProperty("Text"),

ToolboxData("<{0}:LabelMaskEdit runat=server></{0}:LabelMaskEdit>")]

public class LabelMaskEdit : System.Web.UI.WebControls.WebControl

{

private Label label;

private WebMaskEdit textBox;

[Bindable(true), Category("Appearance"), DefaultValue("")]

public string LabelText

{

get

{

EnsureChildControls();

return label.Text;

}

set

{

EnsureChildControls();

label.Text = value;

}

}

[Bindable(true), Category("Appearance"), DefaultValue("")]

public string Text

{

get

{

EnsureChildControls();

return textBox.Text;

}

set

{

EnsureChildControls();

textBox.Text = value;

}

}

protected override void CreateChildControls()

{

label = new Label();

this.Controls.Add(label);

textBox = new WebMaskEdit();

this.Controls.Add(textBox);

}

}

}

It does not give me an error when I drop it on a form.
But I am not getting to much of my control either.
All I see is a label that I cannot assign a text to.
I dont see a text box at all.
What I want is to see text box with all its properties in a property window.
For a label just a text is fine.
How can I do that?
Also when I change something in my customcontrol do I need to remove it
from the form and drop on it again? (Not what I would expect).

Thanks much for help.





Victor Garcia Aprea said:
Hi Mark,

If you move the cursor over the error message you should get a tooltip with
a more specific error message, please post that message to help the guessing
game.

Also note that children controls of a composite control should always be
created in an overriden CreateChildControls methods and not when declaring
the fields as you are doing.

--
Victor Garcia Aprea
Microsoft MVP | ASP.NET
Looking for insights on ASP.NET? Read my blog:
http://obies.com/vga/blog.aspx
My profile: http://aspnet2.com/mvp.ashx?vga


Mark Goldin said:
I am trying to create my first composite control.

Here is the code:

using System;

using System.Collections;

using System.ComponentModel;

using System.Web.UI;

using System.Web.UI.WebControls;

namespace CompositeControls

{

[ToolboxData("<{0}:LabelMaskEdit
runat=server> said:
public class LabelMaskEdit : Table, INamingContainer

{

protected Label LabelName = new Label();

protected Infragistics.WebUI.WebDataInput.WebMaskEdit SearchTextBox = new
Infragistics.WebUI.WebDataInput.WebMaskEdit();


}

}

After I complied the control I can add it to Toolbar with no problem but
when I add the control from Toolbar to aspx page I see a box with "Error
creating control ..."

Can someone help, please?
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top