c# barcode maker Lesson 2: Creating Custom Web Server Controls in C#

Make QR in C# Lesson 2: Creating Custom Web Server Controls

Lesson 2: Creating Custom Web Server Controls
Encoding Quick Response Code In C#.NET
Using Barcode printer for .NET Control to generate, create QR Code 2d barcode image in .NET applications.
www.OnBarcode.com
QR Code ISO/IEC18004 Recognizer In C#
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
ChAPTER 7
Paint Barcode In Visual C#.NET
Using Barcode creator for Visual Studio .NET Control to generate, create bar code image in VS .NET applications.
www.OnBarcode.com
Barcode Recognizer In C#
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
FigURE 7-8 Custom icons for web server controls can be defined by using the ToolboxBitmap attribute.
QR Code Creation In .NET Framework
Using Barcode drawer for ASP.NET Control to generate, create QR Code JIS X 0510 image in ASP.NET applications.
www.OnBarcode.com
Denso QR Bar Code Generation In .NET Framework
Using Barcode generation for .NET Control to generate, create QR Code 2d barcode image in Visual Studio .NET applications.
www.OnBarcode.com
Providing a Default Property for Your Custom Web Server Control
Creating QR-Code In VB.NET
Using Barcode drawer for Visual Studio .NET Control to generate, create QR-Code image in Visual Studio .NET applications.
www.OnBarcode.com
Data Matrix 2d Barcode Drawer In C#
Using Barcode generation for VS .NET Control to generate, create DataMatrix image in VS .NET applications.
www.OnBarcode.com
You can specify a default property of your control to be focused in the Properties window when the user selects the property in the Visual Studio designer. This is useful if your control has a key property to which you want to draw the developer s attention. You indicate this property for your control by using the DefaultProperty attribute class in the System.ComponentModel namespace. Note that this should not be confused with a default property in Visual Basic or C# that takes a parameter and is often used for the Item property of a collection class. Rather, it simply signifies the property to be focused when the user selects your control in the designer. You apply this attribute at the class level, and simply pass the name of one of your properties to this attribute. The following code shows an example of setting the PromptText property as the default for the LabeledTextBox control.
GS1 - 13 Generation In Visual C#.NET
Using Barcode maker for Visual Studio .NET Control to generate, create EAN / UCC - 13 image in .NET applications.
www.OnBarcode.com
Generating Linear In Visual C#
Using Barcode encoder for VS .NET Control to generate, create 1D image in .NET applications.
www.OnBarcode.com
Sample of Visual Basic Code <DefaultProperty("PromptText")> _ Public Class LabeledTextBox Inherits TextBox Sample of C# Code [DefaultProperty("PromptText")] public class LabeledTextBox : TextBox
Barcode Creation In C#.NET
Using Barcode generation for .NET framework Control to generate, create barcode image in .NET framework applications.
www.OnBarcode.com
Make USPS POSTal Numeric Encoding Technique Barcode In Visual C#.NET
Using Barcode drawer for Visual Studio .NET Control to generate, create USPS POSTNET Barcode image in .NET applications.
www.OnBarcode.com
ChAPTER 7
Barcode Creation In Objective-C
Using Barcode encoder for iPad Control to generate, create barcode image in iPad applications.
www.OnBarcode.com
Code128 Creation In Java
Using Barcode maker for Java Control to generate, create Code 128A image in Java applications.
www.OnBarcode.com
Creating Custom Web Controls
Code39 Drawer In Objective-C
Using Barcode creation for iPhone Control to generate, create Code 39 Extended image in iPhone applications.
www.OnBarcode.com
PDF-417 2d Barcode Maker In Java
Using Barcode maker for Android Control to generate, create PDF 417 image in Android applications.
www.OnBarcode.com
Figure 7-9 shows the resulting design-time experience for a developer. Notice that the custom web server control is selected and its PromptText property is focused in the Properties pane.
Bar Code Generation In .NET Framework
Using Barcode drawer for Reporting Service Control to generate, create barcode image in Reporting Service applications.
www.OnBarcode.com
Create Bar Code In Objective-C
Using Barcode creation for iPhone Control to generate, create barcode image in iPhone applications.
www.OnBarcode.com
FigURE 7-9 The DefaultProperty attribute class is used to indicate a property of your control to be high-
Painting EAN-13 Supplement 5 In Objective-C
Using Barcode drawer for iPad Control to generate, create EAN / UCC - 13 image in iPad applications.
www.OnBarcode.com
Barcode Recognizer In VB.NET
Using Barcode reader for .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
lighted in the Properties window when a user selects the control in the designer.
Defining Attributes for Your Control Properties
There are several attribute classes you can apply to the properties of your control to change how those properties are managed by Visual Studio. Table 7-2 lists some of these key attribute classes.
TAbLE 7-2 Attributes Typically Applied to Control Properties
ATTRibUTE
DEsCRiPTiOn
Bindable
You use the Bindable property to indicate whether a control s property should be bound to data. If you set this value to Bindable(true), the property will be displayed in the DataBindings section of the property grid in Visual Studio. By default, properties are assumed to be Bindable(false). You use the Category attribute to indicate the category (or group) in which the property should be displayed in the Properties window grid when a developer changes the Properties view to Categorized. By default, your properties will show up in the Misc category. For example, you can set Category( Appearance ) to indicate that your property should be shown in the Appearance category in the Properties window grid. (continued)
Category
Lesson 2: Creating Custom Web Server Controls
ChAPTER 7
ATTRibUTE
DEsCRiPTiOn
Description
You use the Description attribute to provide a brief description of your property s usage. This description is shown at the bottom of the Properties pane in Visual Studio when the property is selected. You use the DefaultValue attribute to set a default value for your property. You use the Localizable attribute to indicate whether your property should (or can) be localized. Setting Localizable(true) indicates that the property should be serialized as a localized resource.
DefaultValue Localizable
The following code shows an example of applying some of these properties to the PromptText property of the LabledTextBox control.
Sample of Visual Basic Code <Bindable(True), _ Category("Appearance"), _ Description("Text that describes the purpose of the TextBox."), _ Localizable(True)> _ Public Property PromptText() As String Sample of C# Code [Bindable(true), Category("Appearance"), Description("Text that describes the purpose of the TextBox."), Localizable(true)] public string PromptText { get; set; }
This code indicates that the property can be bound to data and can be localized. It also indicates that the property should be displayed in the Appearance category of the Properties window and provides a description when the user selects the property in the Properties window. Figure 7-10 shows the newly decorated property inside the Properties window.
FigURE 7-10 The PromptText property shown in its category and with its description.
ChAPTER 7
Creating Custom Web Controls
Controlling the Markup Generated for Your Custom Web Server Control
You can further change the way your custom server control behaves when it is dropped onto the webpage by setting the ToolboxData attribute in your control class. This attribute is used to change the markup that is generated by Visual Studio. A common scenario is to set default values for properties on the control inside the generated markup. The following code shows an implementation of the ToolboxData attribute for the LabeledTextBox control.
Sample of Visual Basic Code <ToolboxData( _ "<{0}:LabeledTextBox runat=""server"" PromptText="""" PromptWidth=""100"" Public Class LabeledTextBox Inherits TextBox Sample of C# Code [ToolboxData( @"<{0}:LabeledTextBox runat=""server"" PromptText="""" PromptWidth=""100"" />")] public class LabeledTextBox : TextBox />")> _
In this example, the {0} placeholder contains the namespace prefix as defined by the webpage designer. Notice that the PromptText and PromptWidth attributes are inserted automatically. PromptWidth is assigned the default value of 100. When the control is added to a page, the following markup is generated.
<cc1:LabeledTextBox ID="LabeledTextBox1" runat="server" PromptText="" PromptWidth="100"> </cc1:LabeledTextBox>
You can also provide the namespace prefix that is assigned to your control by the webpage designer by assigning the TagPrefixAttribute of the System.Web.UI namespace to the assembly that contains your custom control. (Visual Studio will assign a default value such as uc1 if you do not.) To do so, you add the following attribute declaration to the AssemblyInfo class file in your control (you might have to create this class file for Visual Basic projects). The following code shows the namespace prefix being changed to muc (my user controls) from cc1 for the controls in the MyUserControls project.
Sample of Visual Basic Code Imports System.Web.UI <Assembly: TagPrefix("MyUserControls", "muc")> Sample of C# Code using System.Web.UI; [assembly: TagPrefix("MyUserControls", "muc")]
With the previous change to the LabeledTextBox control, the @ Register directive will change as follows when a user drags the control onto a page.
Copyright © OnBarcode.com . All rights reserved.