Add Property to Web Control

SeanGraflund
SeanGraflund used Ask the Experts™
on
I want to add a property to a web control .. I know I can do it in code on each page to each control like so..

this.cmdAdd.Attributes.Add("for", "add");

but I want to be able to program each button like so in the HTML code:

<asp:button id="cmdAdd" runat=server for="add"></asp:button>


that for property I'd like to be a member of System.Web.UI.WebControls.Button for every page created in the project ..

thanks,

Sean
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
You can create a WebuserControl and put a Button in that control. Define a property named, lets say, FOR in that control. When user sets the property, it in turn Adds an attribute to the button control.
RexxSenior IT Auditor

Commented:
Something similar to this in a public sub gives you the ability to further program a web button.

     btndelcompany.Attributes.Add("onClick","javascript: return confirm('Are You Sure You Want to Delete this Company?')")

Commented:
You can make a class(ex.:MyButton) deriving from Button and implementing your property and adding the new attribute. This become a new custom WebControl like

<MyButton id="btn" runat="server" MyNewProperty="hello!">

Author

Commented:
mhebert,

Can you give me a detailed example about how to add this custom control including code?  I havn't worked with Custom controls before but have worked with classes?

Thanks,

Sean
Most Valuable Expert 2012
Top Expert 2008

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Answered by naveenkohli

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

TheLearnedOne
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial