Server Controls in ASP.Net
Controls are small creating blocks of the graphical user interface, which adds text boxes, check boxes, buttons, list boxes, labels and numerous other tools, needing which users may add data, create selections and shows their preferences.
Controls are also used for structural jobs, like data access, validation, security, preparing master pages, data manipulation.
ASP.Net uses five kinds of web controls, which are:
- HTML controls
- HTML Server controls
- ASP.Net Server controls
- ASP.Net Ajax Server controls
- User controls and custom controls
ASP.Net server controls are the basic controls used in ASP.Net. These controls again should be related into the given categories:
- Validation controls - these are used to validate user input and work by running client-side script
- Data source controls - these controls provides data binding to different data sources
- Data view controls - these are various lists and tables, which can bind to data from data sources for display
- Personalization controls - these are used for personalization of a page according to the user's preference, based on user information
- Login and security controls - these controls provide user authentication
- Master pages - these provides consistent layout and interface throughout the application
- Navigation controls - these helps in navigation, for example, the menus, tree view etc.
- Rich controls - these shows special functions, for example, FileUpload control, AdRotator control, Calendar control etc.
The basic syntax for needing server controls is:
<asp:controlType ID ="ControlID"
runat="server"
Property1=value1 [Property2=value2] />
|
However, visual studio has the given features, which provides in error free coding:
- Dropping and Dragging of controls in design view
- IntelliSense function that shows and auto-completes the properties
- The properties window to set the property number directly
Properties of the Server Controls
The ASP.Net server defines with a visual aspect are invented from the WebControl class and inherit all the properties, events and function of this class.
The WebControl class itself and some another server controls that are not visually provided, e.g., the XML control or PlaceHolder control etc., are related from the System.Web.UI.Control class.
ASP.Net server controls inherit all function and procedures of the WebControl and System.Web.UI.Control class.
The following table gives the inherited properties, which are useful to all server controls:
Property
|
Description
|
AccessKey
|
Pressing this button with the Alt key moves focus to the control
|
Attributes
|
It's the part of arbitrary attributes (for rendering only) that do not related to properties on the control.
|
BackColor
|
Background colour of page.
|
BindingContainer
|
The control that hass this control's data binding.
|
BorderColor
|
Border colour of page.
|
BorderStyle
|
Border style of page.
|
BorderWidth
|
Border width of page.
|
CausesValidation
|
Shows if it causes validation.
|
ChildControlCreated
|
It Shows whether the server control's child controls have been created.
|
ClientID
|
Control ID for HTML markup.
|
Context
|
The HttpContext object related with the server control.
|
Controls
|
Collection of all controls obtained within the control
|
ControlStyle
|
The type of the Web server control.
|
CssClass
|
CSS class
|
DataItemContainer
|
Sets a reference to the naming file if the naming container adds DataItemContainer.
|
DataKeysContainer
|
Gets a reference to the naming container if the naming container adds IDataKeysControl.
|
DesignMode
|
It Shows whether the control is being used on a design surface.
|
DisabledCssClass
|
Gets or sets the CSS class to apply to the given HTML element when the control is disabled.
|
Enabled
|
Shows whether the control is grayed out
|
EnableTheming
|
Shows whether theming applies to the control.
|
EnableViewState
|
Shows whether the view state of the control is maintained.
|
Events
|
Gets a list of event handler integrate for the control.
|
Font
|
Font of page.
|
Forecolor
|
Foreground colour of page.
|
HasAttributes
|
Shows whether the control has attributes set.
|
HasChildViewState
|
Shows whether the current server control's child controls have any saved view-state settings.
|
Height
|
Height in pixels or %.
|
ID
|
Identifier for the control.
|
IsChildControlStateCleared
|
Shows whether controls contained within this control have control state.
|
IsEnabled
|
Gets a value Showing whether the control is enabled
|
IsTrackingViewState
|
It Shows whether the server control is saving changes to its view state.
|
IsViewStateEnabled
|
It Shows whether view state is enabled for this control.
|
LoadViewStateById
|
It Shows whether the control participates in loading its view state by ID instead of index.
|
Page
|
Page obtaining the control.
|
Parent
|
Parent control.
|
RenderingCompatibility
|
It defines the ASP.NET version that rendered HTML will be compatible with.
|
Site
|
The container that hosts the present control when rendered on a design surface.
|
SkinID
|
Sets or gets the skin to apply to the control. (
|
Style
|
Gets a part of text attributes that will be offered as a style attribute on the outer tag of the Web server control.
|
TabIndex
|
Sets or gets the tab index of the Web server control.
|
TagKey
|
Gets the HtmlTextWriterTag value that related to this Web server control.
|
TagName
|
Gets the name of the control tag.
|
TemplateControl
|
The template that has this control.
|
TemplateSourceDirectory
|
Gets the virtual directory of the Page or control having this control.
|
ToolTip
|
Sets or gets the text shown when the mouse pointer hovers over the Web server control.
|
UniqueID
|
Unique identifier
|
ViewState
|
Gets a dictionary of state data that allows you to store and save the view state of a server control across multiple requests for the same page.
|
ViewStateIgnoreCase
|
It Shows whether the StateBag object is case-insensitive.
|
ViewStateMode
|
Gets or sets the view-state mode of this control.
|
Visible
|
It Shows whether a server control is visible.
|
Width
|
Sets or gets the width of the Web server control.
|
Methods of the Server Controls
The following table provides the methods of the server controls:
Method
|
Description
|
AddAttributesToRender
|
Includes HTML attributes and styles that require to be rendered to the specified HtmlTextWriterTag.
|
AddedControl
|
Called after a child control is included to the Controls collection of the Control object.
|
AddParsedSubObject
|
Shows the server control that an element, either XML or HTML, was parsed, and includes the element to the server control's control collection.
|
ApplyStyleSheetSkin
|
Defines the style properties described in the page style sheet to the control.
|
ClearCachedClientID
|
Infrastructure. Assign the cached ClientID value to null.
|
ClearChildControlState
|
Removes the control-state information for the server control's child controls.
|
ClearChildState
|
Removes the view-state and control-state information for all the server control's child controls.
|
ClearChildViewState
|
Removes the view-state information for all the server control's child controls.
|
CreateChildControls
|
Used in creating child controls.
|
CreateControlCollection
|
Build a new ControlCollection object to hold the child controls.
|
CreateControlStyle
|
Build the style object that is used to implement all style related properties.
|
DataBind
|
Relates a data source to the server control and all its child controls.
|
DataBind(Boolean)
|
Relates a data source to the server control and all its child controls with an option to raise the DataBinding event.
|
DataBindChildren
|
Relates a data source to the server control's child controls.
|
Dispose
|
Actives a server control to perform final clean up before it is released from memory.
|
EnsureChildControls
|
Calculates whether the server control contains child controls. If it does not, it creates child controls.
|
EnsureID
|
Prepare an identifier for controls that do not have an identifier.
|
Equals(Object)
|
Calculates whether the specified Object is equal to the current Object.
|
Finalize
|
Allows an Object to attempt to free sources and perform other cleanup operations before the Object is reclaimed by garbage collection.
|
FindControl(String)
|
Finds the current naming container for a server control with the specified id parameter.
|
FindControl(String, Int32)
|
Finds the current naming container for a server control with the specified id and an integer
|
Focus
|
Sets input focus to a control button.
|
GetDesignModeState
|
Gets design-time data for a control.
|
GetType
|
Gets the kind of the current instance.
|
GetUniqueIDRelativeTo
|
Gives the prefixed portion of the UniqueID property of the related control.
|
HasControls
|
Calculates if the server control contains any child controls.
|
HasEvents
|
Shows whether events are registered for the control or any child controls.
|
IsLiteralContent
|
Calculates if the server control holds only literal content.
|
LoadControlState
|
Restores control-state information.
|
LoadViewState
|
Restores view-state information.
|
MapPathSecure
|
Gets the physical path that a virtual path, either relative or absolute, maps to.
|
MemberwiseClone
|
Prepares a shallow copy of the current object.
|
MergeStyle
|
Copies any nonblank components of the specified style to the Web control, but will not overwrite any existing style components of the control.
|
OnBubbleEvent
|
Calculates whether the event for the server control is passed up the page's UI server control hierarchy.
|
OnDataBinding
|
Raises the data binding event on page.
|
OnInit
|
Increases the Init event.
|
OnLoad
|
Increases the Load event.
|
OnPreRender
|
Increases the PreRender event.
|
OnUnload
|
Increases the Unload event.
|
OpenFile
|
Gets a Stream used to read a file
|
RemovedControl
|
Invoked after a child control is replaced from the Controls collection of the Control object.
|
Render
|
Renders the control to the defined HTML writer.
|
RenderBeginTag
|
Renders the HTML related tag of the control to the specified writer.
|
RenderChildren
|
Outputs the content of a server control's children to a given HtmlTextWriter object, which writes the content to be rendered on the client.
|
RenderContents
|
Renders the contents of the control to the given writer.
|
RenderControl(HtmlTextWriter)
|
Outputs server control content to a given HtmlTextWriter object and restores tracing data about the control if tracing is enabled.
|
RenderEndTag
|
Renders the HTML ending tag of the control into the specified writer.
|
ResolveAdapter
|
Gets the control adapter responsible for rendering the related control.
|
SaveControlState
|
Saves any server control state modifies that have occurred since the time the page was posted back to the server.
|
SaveViewState
|
Saves any state that was changed after the TrackViewState method was invoked.
|
SetDesignModeState
|
Sets design-time data for a control.
|
ToString
|
Returns a String that shows the current object.
|
TrackViewState
|
Causes the control to track modifies to its view state so they can be stored in the object's view state property.
|
Example:
Let us look at a various server control - a tree view control. A Tree view control related under navigation controls. Other Navigation controls are: SiteMapPath control and Menu control.
Add a tree view control on the page. Checks Edit Nodes... from the tasks. Edit each of the nodes taking the Tree view node editor:
Once you have prepared the nodes, it looks like the given in design view:
The AutoFormat... task gives you to format the tree view:
Add a text box control and a label control on the page and name them txtmessage and lblmessage respectively.
Write few lines of code to takes that when a particular node is chosen, the label control shows the node text and the text box shows all child nodes under it, if any. The code related file could look like this:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace eventdemo
{
public partial class treeviewdemo : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
txtmessage.Text = " ";
}
protected void TreeView1_SelectedNodeChanged(object sender,
EventArgs e)
{
txtmessage.Text = " ";
lblmessage.Text = "Selected node changed to: " +
TreeView1.SelectedNode.Text;
TreeNodeCollection childnodes =
TreeView1.SelectedNode.ChildNodes;
if(childnodes != null)
{
txtmessage.Text = " ";
foreach (TreeNode t in childnodes)
{
txtmessage.Text += t.Value;
}
}
}
}
}
|
Execute the page to see the effects. You will be able to illustrate and control the nodes.
Email based ASP.Net assignment help - homework help at Expertsmind
Are you searching ASP.Net expert for help with Server Controls in ASP.Net questions? Server Controls in ASP.Net topic is not easier to learn without external help? We at www.expertsmind.com offer finest service of ASP.Net assignment help and ASP.Net homework help. Live tutors are available for 24x7 hours helping students in their Server Controls in ASP.Net related problems. Computer science programming assignments help making life easy for students. We provide step by step Server Controls in ASP.Net question's answers with 100% plagiarism free content. We prepare quality content and notes for Server Controls in ASP.Net topic under ASP.Net theory and study material. These are avail for subscribed users and they can get advantages anytime.
Why Expertsmind for assignment help
- Higher degree holder and experienced experts network
- Punctuality and responsibility of work
- Quality solution with 100% plagiarism free answers
- Time on Delivery
- Privacy of information and details
- Excellence in solving ASP.Net queries in excels and word format.
- Best tutoring assistance 24x7 hours