Skip to main content

Posts

Showing posts from October, 2008

How to use Button ClientClick event in asp.net

Button ClientClick event The Button web server control displays a push button control on the Web page. The Button lets users post a page to the server. The control triggers an event in server code that asp.net developers can handle to respond to the postback. The Button can also raise an event in the client script that developers can handle before the page is posted or that can run and then cancel the submission of the page. The following asp.net c# tutorial code demonstrates how we can trigger the Button ClientClick event. In this tutorial, we showed an alert message on the web browser using the Button ClientClick event. The developers have to set the Button OnClientClick property to use the ClientClick event. The Button OnClientClick property gets or sets the client-side script that executes when a Button control's Click event is raised. This property value is a String which is the client-side script that executes when a Button control...

ASP.NET Web.sitemap file Example

A sample Web.sitemap file Web.sitemap <?xml version="1.0" encoding="utf-8" ?> <siteMap xmlns="http://schemas.microsoft.com/AspNet/SiteMap-File-1.0" > <siteMapNode url="Default.aspx" title="Home" description="Home Page"> <siteMapNode url="StandardToolBox.aspx" title="StandardToolBox" description="StandardToolBox Controls"> <siteMapNode url="AdRotatorExample.aspx" title="AdRotator" description="AdRotator Example" /> <siteMapNode url="BulletedListExample.aspx" title="BulletedList" description="BuulletedList Example" /> <siteMapNode url="ButtonExample.aspx" title="Button" description="Button Example" /> <siteMapNode url="CalendarExample.aspx" title="Calendar" description="Calendar Example...

How to use LoggedInTemplate and AnonymousTemplate in LoginView

LoggedInTemplate and AnonymousTemplate in LoginView Control LoginView is an asp.net web server control. LoginView control displays the appropriate content template for a given user, based on the user authentication status and role membership. The LoginView control includes two templated views that are displayed to the user. Those are AnonymousTemplate and LoggedInTemplate. AnonymousTemplate is displayed to the users who are not logged in. Anonymous users are those who are not logged in. LoggedInTemplete is displayed for logged-in users only. We can also create templates for the members of particular logged-in role groups. The following asp.net example code demonstrates to us how can we create different templates for authenticated users and anonymous users in an asp.net application. In the below example code, we created two templates view for authenticated users and anonymous users. When authenticated users visit the specified page, they...

How to use ChangePassword control in asp.net

ChangePassword Web Server Control ChangePassword is an ASP.NET web server control. ChangePassword control enables website users to change the passwords they use to log in to the website. ChangePassword server control uses the membership provider defined by the MembershipProvider property to change the password stored in the membership provider data store. ChangePassword control uses the default membership provider if a membership provider does not assign by web developers. We can configure ChangePassword control to use email services to send the new password to the user. To send users a new password to their email address, we must configure an email server in the Web.config file for an ASP.NET application. ChangePassword control has two states or views, the change password view and the success view. The change password view requests the current password and requires inputting the new password twice. The success views display confirmation t...

How to login users programmatically in asp.net

Login user programmatically In .net framework Membership class’s ValidateUser() method allows us to programmatically verify the supplied username and password are valid. The Membership class’s ValidateUser(username, password) method exists under the System.Web.Security namespace. This method requires passing two parameters. The first parameter name is 'username' and another parameter name is 'password'. Both parameters’ data type is String. The username parameter value passes the name of the user to be validated and the password parameter value passes the password for the specified user. If the username parameter is null or empty then this method throws an HttpException. This method returns a Boolean value. If the supplied username and password are valid then it returns True, otherwise, it returns false. In this example code, we manually build a login page without Login server control. This login page contains two TextBoxes...

How to show login status in asp.net

LoginStatus Web Server Control .NET framework LoginStatus Class allows us to detect the user's authentication state and toggles the state of a link to log in to or log out of a website. To allow users to log in to an ASP.NET application that uses forms authentication, we can use the LoginStatus server control to detect a user authentication status. When this control found a user is not authenticated then it displays a Button to move the user to the login page. If the control found a login user then it displays a logout button for this user to log out from the website. We can customize the default look and feel of LoginStatus control by setting its various properties such as BackColor, ForeColor, BorderStyle, BorderColor, BorderWidth, CssClass, Font, Height, Width, etc. LoginStatus control's LoginImageUrl property allows us to set the URL of the image used for the login page link. LoginText property set the text display for the logi...

How to show login name in asp.net

Show login name in asp.net LoginName is an ASP.NET web server control. LoginName control allows us to display a user's login name if the user has logged in using ASP.NET membership. If the site uses integrated windows authentication, the LoginName control displays the user's windows account name. LoginName class allows us to display System.Web.UI.Page.User.Identity.Name property value. LoginName class exists in System.Web.UI.WebControls namespace. LoginName control has many useful built-in properties to provide a better user experience such as AccessKey, BackColor, BorderColor, Attributes, BorderStyle, BorderWidth, CssClass, Font, ForeColor, FormatString, HasAttributes, Height, IsEnabled, Page, Parent, SkinID, Style, TabIndex, TagKey, ToolTip, ViewState, Visible, Width, etc. LoginName control has a few events such as DataBinding, Disposed, Int, Load, PreRender, and Unload. LoginName class’s FormatString property allows us to ...

How to create Login page in asp.net

Login Web Server Control In an asp.net application, we can create a user login page by using Login web server control. This Login control displays a user interface for user authentication. Login control renders two TextBoxes to input username and password. It also displays a CheckBox that allows users to indicate whether they want the server to store their identity for the next visit. It allows users to be automatically authenticated for the next visit. The Login control has many useful built-in properties to customize it. We can change the default look and feel of the login page by using the Login control's BackColor, BorderColor, BorderWidth, BorderStyle, CheckBoxStyle, CreateUserIconUrl, CreateUserText, CreateUserUrl, CssClass, Font, ForeColor, FailureTextStyle, Height, HelpPageIconUrl, LayoutTemplate, TextBoxStyle, TitleTextStyle, LabelStyle, InstructionTextStyle, HyperLinkStyle, LoginButtonStyle, ValidatorTextStyle, BorderPadding, and many mo...

asp.net - How to submit a page to another page

Submit a page to another page in asp.net The Button is an ASP.NET web server control. By default, a Button control is a submit Button, and by clicking the submit Button the ASP.NET page submits the page back to itself. Sometimes ASP.NET developers want to post one page to another page. This is useful for creating multi-page forms. We can configure the Button control to post the current page to another page. This is called cross-page posting. We can also use Wizard server control to create multi-view forms. We can configure cross-page posting for individual Buttons, so we can create a page that posts to different pages depending on which Button the user clicks. The Button control's PostBackUrl property gets or sets the URL of the page to post from the current page when the Button control is clicked. By default, this property value is an empty string that causes the page to post back to the same page. We need to set the target page URL as t...

How to add an item to ListBox programmatically in asp.net c#

Add an item (ListItem) to ListBox The following ASP.NET C# example code demonstrates to us how can we add an item to ListBox control programmatically at run time. ListBox is an ASP.NET list web server control. ListBox contains items collection. Each item of ListBox control represents a ListItem object. We can add ListItem object to ListBox control's items collection both statically and programmatically. To add an item to ListBox control programmatically, we can call the Collection Class’s Add() method. This Add() method allows us to add an item to a collection. So we can easily add an item to the ListBox control as the Items Add(ListItem) method. Because ListBox contains an items collection that supports the addition of new items. To Add an item (ListItem) to a ListBox control, first, we need to create the ListItem object. Each ListItem object has a Text property and optionally a Value property. We can also set the specified ListItem object ...

How to use ValidationSummary control in asp.net

ValidationSummary web server control ValidationSummary control allows us to display the summary of all validation errors. We can display validation errors summary inline of a web page or a message box or both by using ShowMessageBox and ShowSummary property value true or false. We can display validation messages as bulleted lists, single paragraphs, or only lists based on DisplayMode. We can set a header text for the validation summary. ASP.NET ValidationSummary control has many properties to design the error messages text as fore color, back color, border color, border style, border width, theme, skin, and after all CSS class. ValidationSummary allows a summary of all validation error messages from all validators in a single location. This example shows you how can we display all validation error messages as a summary using the ValidationSummary control. Here we use three text boxes and make them required fields using RequiredFieldValid...

ASP.NET - Using SetFocusOnError property in validation control

Set focus on error in validation The following asp.net c# tutorial code demonstrates how we can set the focus on error in validation. In this tutorial, we used the RequiredFieldValidator control to validate TextBox. In the RequiredFieldValidator web server control, we set focus on the error feature. The RequiredFieldValidator web server control makes the associated input control a required field. The RequiredFieldValidator SetFocusOnError property gets or sets a value that indicates whether the focus is set to the control specified by the ControlToValidate property when validation fails. The SetFocusOnError property value is a Boolean. This property value is true to set focus on the control specified by ControlToValidate when validation fails otherwise its value is false. The default is false. So the asp.net c# developers can enable focus on error feature by using this SetFocusOnError property in validation control. They just have to set the S...

ASP.NET Validation - How to disable client script

Disable client script in validation The following asp.net c# tutorial code demonstrates how we can disable the client script in validation. In this tutorial, we used a RequiredFieldValidator control to validate a TextBox. In the RequiredFieldValidator web server control, we disabled the client script. The RequiredFieldValidator web server control makes the associated input control a required field. The RequiredFieldValidator EnableClientScript property gets or sets a value indicating whether client-side validation is enabled. The EnableClientScript property value is a Boolean. This property value is true if client-side validation is enabled otherwise the value is false. The default value is true. So, using this EnableClientScript property, the asp.net developers can disable the client script while validating the web page. They just have to set this property value to false. The asp.net c# developers can use the EnableClientScript property...

asp.net c# RadioButtonList control example

RadioButtonList control example RadioButtonList is an ASP.NET list web server control. RadioButtonList control renders a group of radio button controls where each radio button shares the same group name. RadioButtonList control encapsulates a radio group. RadioButtonList control each ListItem object is renders a single radio button control. RadioButtonList control's items exist in an items collection. So we can manage (edit, insert, and delete) RadioButtonList item collection by the .NET framework's Collection Class methods and properties. RadioButtonList control has many built-in properties to design and style the control itself such as BackColor, ForeColor, CssClass, etc. We also can customize its items level style by core CSS style such each different colors for different items. RadioButtonList control's AutoPostBack property and SelectedIndexChanged event allow us to quickly get the user's item selection after each tim...

How to use MultiView control in asp.net

MultiView and View Server Control MultiView is an asp.net web server control. The View control is also an asp.net web server control. But view control always is contained within multiview control. Both multiview and view control act as a container for other controls and markup. Only one view can be defined as an active view in MultiView. MultiView ActiveViewIndex property specifies the active view within view collections of a multiview. Only active view control is rendered to the page. We can navigate views by setting the multiview ActiveViewIndex property value. ActiveViewIndex property holds the specified view's index number. MultiView control can include navigation buttons that we can add to each view. We can create a navigation button by adding any Button, LinkButton, or ImageButton server control to each view. For that, we need to set the CommandName and CommandArgument properties of each view. Reserved CommandName values are NextView...

How to use TreeView in asp.net

TreeView Server Control TreeView is an asp.net web server control. TreeView displays hierarchical data such as a table of contents or files directory, in a tree structure. TreeView control is made up of nodes. We can display static data in a TreeView by creating a collection of TreeNode elements as children of the TreeView. We can bind TreeView to a data source such as XmlDataSource and SiteMapDataSource. TreeView can also be bound to an XmlDocument object or a DataSet object. TreeView node types are the parent node, child node, leaf node, and root node. The Parent node contains other nodes. child node is contained by another node and the leaf node have no children node. The root node is not contained by any other node. Node has two properties Text and Value. text property value displayed in the browser and the value property is hidden in the browser and stores any additional data about the node. a node can have one mode selection mode o...

How to validate a DropDownList in asp.net

DropDownList Validation DropDownList is an asp.net list web server control that allows us to select a single item from a drop-down list at a time. DropDownList control contains ListItem objects. The following asp.net c# example code demonstrates to us how can we validate a DropDownList control in a web form. When users submit a form without changing the selection of DropDownList items, then the first item is posted to the server as a selected item if there is no initial selected item. Normally web developers put an instruction-only item at the DropDownList items top such as an item with the text 'select an item' etc. So web developers need to ensure that users select an item from DropDownList control other than the first item. We can validate a DropDownList server control using the RequiredFieldValidator control. RequiredFieldValidator is an asp.net validation server control that makes the associated input control a required field. We ca...

ASP.NET CompareValidator - How to validate Data Type

Validate data type using CompareValidator The CompareValidator class compares the value entered by the user in an input control with the value entered in another input control or with a constant value. The following asp.net c# tutorial code demonstrates how we can validate a data type using CompareValidator. In this example code, we will validate the integer data type. We will check the user input an integer value for the age field or not using the CompareValidator. The CompareValidator ControlToCompare property gets or sets the input control to compare with the input control being validated. This property value is a String which is the input control to compare with the input control being validated. The default value is Empty. The asp.net c# developers have to use the ControlToCompare property to specify an input control, such as a TextBox control, to compare with the input control being validated. The CompareValidator Operator...

How to use CompareValidator control in asp.net

CompareValidator CompareValidator control compares user inputted value with another input control value or a constant value. CompareValidator validation success if the inputted value matches the criteria specified by the Operator, ValueToCompare, or ControlToCompare property. CompareValidator Type property indicates whether inputted value needs to be converted to a specified data type (string, date, currency, double, or integer). The controlToValidate property indicates which control needs to validate. ControlToCompare property indicates which control needs to compare with inputted value (such as TextBox value). ValueToCompare property indicates that you want to compare the inputted value with a constant value instead another control value. Don't put ControlToValidate and ValueToCompare properties together in a CompareValidator control. You can use any one property at a time. That means you can only compare with a control or compare with ...

How to use RadioButtonList control in asp.net c#

RadioButtonList web server control ASP.NET RadioButtonList control enables the user to select an item from the list. RadioButtonList supports data binding programmatically from the database. We can also populate it manually by inputting a list of items inside the RadioButtonList tag. RadioButtonList is a single selection radio button group. RadioButtonList has an item collection. We can determine which item is selected by testing its SelectedItem property. We can change RadioButtonList design by setting up its various property as like BackColor, BorderColor, BorderStyle, BorderWidth, CellPadding, CellSpacing, CssClass, Font-Bold, Font-Italic, Font-Names, Font-Overline, Font-Size, etc. there are more three properties RepeatColumns, RepeatDirection, and RepeatLayout which help you to place list item vertically or horizontally. RadioButtonList has standard AutoPostBack property. As with other list control, RadioButtonList has an excellent event Sel...

How to use RadioButton control in asp.net c#

RadioButton web server control The RadioButton control lets you make a group of radio buttons with other RadioButton. If you set its GroupName property to the same for multiple radio buttons then all radio buttons with the same name act as a single group. Within a group, you can only select one RadioButton at a time. RadioButton group work as like RadioButtonList. With RadioButton control you can more customize it than RadioButtonList items. Back color, border color, border style, font names, font bold, font italic, fore color (text color), and much more property help you to design RadioButton. It also supports CSS class, theme, and skin. Even validation works with RadioButton control. RadioButton has an AutoPostBack property and a CheckChanged event. By using those features you can determine immediately which RadioButton is selected from a group. This example uses a RadioButton group with two RadioButton. Here we assign the AutoPostBack prope...