views:

64

answers:

4

Hello,

I was wondering if there is a way to set by default the value of an attribute for all specific asp:object

As an example: Set the text property for all asp:TextBox objects in the web application to "Please insert text"

This example is not what I am trying to achieve, just an example to clarify.

Thanks :)

+2  A: 

You could derive from the usercontrol and set the Text property in the constructor.

James
I could, but the application is already built and there are quite a few objects I needed to change... I was looking for a way to avoid this extra work.
Sergio
Perhaps some javascript?
James
+2  A: 

You may be able to accomplish what you need using Themes.

Chris Shaffer
That works perfectly :) thanks
Sergio
A: 

You could create a TextBoxAdapter that changes the Text property before rendering the control.

Take a quick look at Architectural Overview of Adaptive Control Behavior at MSDN. Read about Control Adapters, they can do what you want.

Simon Svensson
A: 

Derive a control, and then use the little known tagMapping feature to replace it across the app.

 class MyTextBox : TextBox {
     public MyTextBox() : base() {
        this.Text = "Please insert text";
     }
 }

 <pages>
    <tagMapping>
       <add tagType="System.Web.UI.WebControls.TextBox"
        mappedTagType="MyTextBox, MyWebControls.dll" />
    </tagMapping>
 </pages>
Mark Brackett