|
There are several different groups of controls in ASP.Net, ranging from the foundational HtmlControls to the advanced Custom Server Controls:
While everything ultimate reduces to Html, grouping controls together for reusable packages lets us save a lot of time. One such technique is to create an Extended Control by inheriting from an already existing control. This is great for when you want to build off a single control and extend its functionality. For example you could inherit from the TextBox class and add a new method ToLower which makes all the text lowercase.
There are several benefits
This is easy to do, here's how:
using System; using System.Web.UI.WebControls; namespace WebControlLibrary1 { /// <summary> /// Summary description for TextBoxA. /// </summary> public class TextBoxA : System.Web.UI.WebControls.TextBox { public TextBoxA() { } public void ToLower() { this.Text = this.Text.ToLower(); } public string NewProp { get { if (ViewState["NewProp"] == null) return ""; else return ViewState["NewProp"].ToString(); } set { ViewState["NewProp"] = value; } } } //end of class } |
In the code snippet, we've added a method ToLower which references the textbox property "Text" and makes it lowercase. We've also created an arbitrary property NewProp and made it save data using ViewState.
We can load this easily into Aspx pages by first adding the DLL to the project like any other reference, and then adding the control itself to the toolbox. This lets us perform drag & drop operations like any other WebControl.
If you don't want to add it to your toolbox, then you can also directly type the Html. You need to first Register the assembly by putting something like this at the top:
|
And then reference the control in the page by:
|
In summary, this is a quick technique with high return, and therefore a good skill to have.
Tim
I saw your server side confirm button at
http://www.timstall.com/Code.aspx. Can you tell me if the Button assembly
code is available for people who download the test code. If yes please let
me know , I would like to implement the code in C# or if u can mail be the
the Button class code I would be grateful I am in great need of this, but I
wouldnt like to use the assembly would rather prefer the code compile as
part of my code . Please let me know if you will allow me on the
same
Thanks
Hello,
Okay. I've just put this in a recent blog post
at:
http://timstall.dotnetdevelopersjournal.com/read/1241430.htm
Hey Parithi, I don't have it in VB, but it's easy C# that should be almost
a direct translation - there's no C# specific concepts there.
Hi Parithi
Another option is get hold of the c# code as posted by Tim, compile it into
a dll then download a useful utility like Reflector.Net, then disassemble
the dll into VB.Net or delphi which ever u need
It is nice to know about customcontrols for beginners
plz help us be nice to you guys dont be bad plz