In one. NET application, you can greatly enhance the functionality of your application by adding the properties and behaviors you want to the original control, or even creating your own custom controls. In asp.net, we can increase the functionality and efficiency of the program by adding some client-side JavaScript functionality to the previous controls, reducing the number of times the data is returned to the server each time the page is submitted. In this article, we'll look at how to create a custom text box control with asp.net that changes the background color of the text box control when the focus is on the text box control and when you leave the control. This control will contain the following features:
1 when a user enters data in a text box, the background color of the text box is displayed in a preset color, and the background color of the original text box can be restored when the user's input focus leaves the text box.
2 The various properties of the custom control can be changed during the design of the vs.net.
Let's start by creating the control step-by-step. First, create an empty vs.net solution, add a asp.net project (named WebApplication) and a Web Control Library project (named Controlib). Rename the WebForm1.aspx in the ASP.net project to container.aspx, and rename the Webcustomercontrol1.cs in the Web Control Library project to PimpedOutTextbox.cs.
Next, add the code to the Pimpedouttextbox class. Because this is a Web control library, VS. NET has introduced a related class library. Since our application will use color features, we introduce a drawing class.
Using System.Drawing;
Replace the previously predefined code with the following code.
Line 1: [Assembly:tagprefix ("Controllib", "Lib")]
Line 2:namespace Controllib
Line 3: {
Line 4: [Defaultproperty ("Backcoloron"),
Line 5:toolboxdata ("<{0}:P impedouttextbox runat=server></{0}:P impedouttextbox>")]
Line 6:public class PimpedOutTextbox:System.Web.UI.WebControls.TextBox
Line 7: {
At the outset, the Assembly property was added, which is designed to automatically add TagPrefix control markup when the control is dragged in vs.net. In the Pimedouttexbox class, Added several properties: the attribute Backcoloron in Defaultproperty and toolboxdata.defaultproperty means that when the control is dragged from the Vs.net Toolbox to the designer, the property is selected by default in the control. The ToolBoxData property is related to the [Assembly:tagprefix] property and is used to indicate how the control was generated from the HTML view. These properties are explained in more detail below.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service