Composite Control Attributes

A

Alphonse Giambrone

I am building a composite control in C# that contains a textbox and a
requiredfieldvalidator that I want to be able to add client side attributes
to.

If I use mycontrol.Attributes.Add(.....) the attributes are added to the
span element in the generated html.
How can I apply attributes to the composite control so that they are added
to the textbox that is contained in my control?

TIA
 
V

Victor Garcia Aprea [MVP]

Hi Alphonse,

Use the Attributes property of your textbox child and not that of the
composite control itself.
 
A

Alphonse Giambrone

Thanks for the reply Victor.
I understand that I can add attributes to the textbox from within the
composite control by using txt1..Attributes.Add(.....) .
How can I expose this via the composite?
A small example would be great.

TIA

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us
 
V

Victor Garcia Aprea [MVP]

Try something like this:

[C#]
public AttributeCollection TextBoxAttributes {
get {
// you may need to ensure children are created are
return textBox.Attributes;
}
}

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

Alphonse Giambrone

Thanks for the quick reply and help..
I guess I was not too clear. I want to be able to add attributes to the
textbox that is contained within my control from the rendering page, but you
did give me an idea.
I added a public method to my control and that works.

[Description("Add attributes to the textbox")]
public void AddAttribute(string key, string _value)

{

EnsureChildControls();

txt1.Attributes.Add(key,_value);

}

I can use it from code behind, similar to
anyothercontrol.Attributes.Add(.....)

BTW check you blog link.
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


Victor Garcia Aprea said:
Try something like this:

[C#]
public AttributeCollection TextBoxAttributes {
get {
// you may need to ensure children are created are
return textBox.Attributes;
}
}

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


Alphonse Giambrone said:
Thanks for the reply Victor.
I understand that I can add attributes to the textbox from within the
composite control by using txt1..Attributes.Add(.....) .
How can I expose this via the composite?
A small example would be great.

TIA
 
V

Victor Garcia Aprea [MVP]

Glad I could help!

fixed now. thanks!

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


Alphonse Giambrone said:
Thanks for the quick reply and help..
I guess I was not too clear. I want to be able to add attributes to the
textbox that is contained within my control from the rendering page, but you
did give me an idea.
I added a public method to my control and that works.

[Description("Add attributes to the textbox")]
public void AddAttribute(string key, string _value)

{

EnsureChildControls();

txt1.Attributes.Add(key,_value);

}

I can use it from code behind, similar to
anyothercontrol.Attributes.Add(.....)

BTW check you blog link.
--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


Victor Garcia Aprea said:
Try something like this:

[C#]
public AttributeCollection TextBoxAttributes {
get {
// you may need to ensure children are created are
return textBox.Attributes;
}
}

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


Alphonse Giambrone said:
Thanks for the reply Victor.
I understand that I can add attributes to the textbox from within the
composite control by using txt1..Attributes.Add(.....) .
How can I expose this via the composite?
A small example would be great.

TIA

--

Alphonse Giambrone
Email: a-giam at customdatasolutions dot us


Hi Alphonse,

Use the Attributes property of your textbox child and not that of the
composite control itself.

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


I am building a composite control in C# that contains a textbox
and
 

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,754
Messages
2,569,527
Members
44,998
Latest member
MarissaEub

Latest Threads

Top