<script language="vb" runat="server"> Sub Page_Load() time.text=Hour(Now) & ":" & Minute(Now) & ":" & Second(Now) End Sub </script> <html> <head><title>The Punctual Web Server</title></head> <body> <h1>Welcome</h1> In WebServerLand the time is currently: <asp:label id="time" runat="server" /> </body> </html>
ASP.NET AdRotator Control is used to display a set of images in a sequence which can be used as an Advertisment. ASP.NET AdRotator Control uses an XML file to store the information for the advertisement. This XML file must begin and end with an <Advertisement> tag. Within the<Advertisement> tags there may be many <Ad> tags which can be used to define different advertisements.
The following ASP.NET Tutorial teaches you how to use an ASP.NET AdRotator Control.
- Go to the Toolbox and under the Standard section, select AdRotator Control.
ASP.NET AdRotator Control
- Drag and drop it onto the Form area to declare it.
- The following is the code excerpt you get in the Source View.
<asp:AdRotator ID="AdRotator1" runat="server" />
- The following is shows an example use of the ASP.NET AdRotator Control.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:AdRotator ID="AdRotator1" AdvertisementFile="~/ad1.xml" runat="server" OnAdCreated="change_url" target="_blank" />
<p><a href="ad1.xml" target="_blank">View XML file</a></p>
</div>
</form>
</body>
</html>
- Add the following code to the Code behind file (Default.aspx.vb)
Protected Sub change_url(ByVal sender As Object, ByVal e As AdCreatedEventArgs)
e.NavigateUrl = "http://www.aspnetbook.com"
End SubNote:
- An event handler is created for the “AdCreated” event in the “.aspx” file.
- This overrides the value of the “NavigateURL” element in the XML file.
- The following is the code for the “Ad1.xml” XML file
<Advertisements>
<Ad>
<ImageUrl>/banners/ad1.gif</ImageUrl>
<NavigateUrl>http://www.aspnetbook.com</NavigateUrl>
<AlternateText>Main Site</AlternateText>
<Impressions>10</Impressions>
<Keyword>Keywords Here</Keyword>
</Ad>
<Ad>
<ImageUrl>/banners/ad2.jpg</ImageUrl>
<NavigateUrl>http://www.aspnetbook.com/index.asp</NavigateUrl>
<AlternateText>Main Page</AlternateText>
<Impressions>10</Impressions>
<Keyword>Keywords Here</Keyword>
</Ad>
</Advertisements>
The following are the predefined elements inside the <Ad> tag.
Element
|
Description
|
<ImageUrl>
|
An Optional Element used to define the path of the Image file.
|
<NavigateUrl>
|
An Optional Element used to define the URL to link to if the user clicks the ad.
|
<AlternateText>
|
An Optional Element used to define an alternate text for the Image file.
|
<Keyword>
|
An Optional Element used to define a category for the Advertisement.
|
<Impressions>
|
An Optional Element used to display rates in percent of hits.
|
The following table shows the Properties available for the <Ad> tag.
Property
|
Description
|
.NET
|
AdvertisementFile
|
To define the path to the XML file this contains the Advertisement information.
|
1.0
|
AlternateTextField
|
To define the path to the data field used instead of the “Alt” text for an Ad.
|
2.0
|
ImageUrlField
|
To define the path to the data field used instead of the “ImageURL” attribute for an Ad
|
2.0
|
KeywordFilter
|
To specify a filter to limit Advertisements after categories.
|
1.0
|
NavigateUrlField
|
To specify the path to the data field used instead of the “NavigateURL” attribute for an Advertisement.
|
2.0
|
runat
|
To specify the control to server control i.e. must be set to “server”.
|
1.0
|
Target
|
To specify where to open the URL
|
1.0
|
ASP.NET Button Control is used to display a Push Button. The ASP.NET Button Control can be used as a:
- Submit Button
- Command Button
ASP.NET Button Control does not have a command name and it posts the Web page back to the server when it is clicked. When using the ASP.NET Button Control you can code an event handler to control the actions performed when the submit button is clicked.
Note:
- By default the ASP.NET Button Control is a Submit button.
- An ASP.NET Button control as a Command button has a command name and allows you to create multiple Button Controls on a page.
- The actions performed when the command button is clicked can be controlled by writing an event handler.
The following is an ASP.NET tutorial on how to use an ASP.NET Button Control.
- Go to the Toolbox and under the Standard section, select Button Control.
ASP.NET Button Control
- Drag and drop it onto the Form area to declare it.
- The following is the code you get in the Source View.
<asp:Button ID="Button1" runat="server" Text="Button" />
- The following is shows an example use of the ASP.NET Button Control.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button id="button1" Text="Click Here" runat="server" OnClick="submit" />
</div>
</form>
</body>
</html>
- Add the following code to the Code behind file (Default.aspx.cs)
protected void submit(object sender, EventArgs e)
{
button1.Text = "Already Clicked Here";
}Note:
- By double clicking the ASP.NET Button Control in the Design View an event handler is created for the “submit” event in the “.aspx.cs” file.
- In this event you can override the value of the “Text” property for the ASP.NET Button control.
The following are the Properties of the ASP.NET Button Control.
Property
|
Description
|
.NET
|
CausesValidation
|
To specify if a page is validated when a button is clicked.
|
1.0
|
CommandArgument
|
To specify information about the command to perform.
|
1.0
|
CommandName
|
To declare the command for the Command event.
|
1.0
|
OnClientClick
|
To declare the name of the function to be executed when a button is clicked.
|
2.0
|
PostBackUrl
|
To declare the URL of the page to post to from the current page when a button is clicked.
|
2.0
|
runat
|
To specify that the control is a server control i.e. must be set to “server”.
|
1.0
|
Text
|
To specify the text for the ASP.NET Button control.
|
1.0
|
UseSubmitBehavior
|
To specify if the ASP.NET button uses the browser's submit mechanism or the ASP.NET postback mechanism
|
2.0
|
ValidationGroup
|
To specify the group of controls a button causes validation when it posts back to the server.
|
2.0
|
ASP.NET Calendar Control can display a calendar in the browser. The ASP.NET Calendar Controlcan display one-month calendar that will show in the browser so that the user viewing the web page can select dates and navigate to the next and previous months as they wish.
The following ASP.NET Tutorial will help you learn how to use an ASP.NET Calendar Control.
- Go to the Toolbox and under the Standard section, select Calendar Control.
ASP.NET Calendar Control
- Drag and drop it onto the Form area to declare it.
- The following is the code you get in the Source View.
<asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
- The following is shows an example use of the ASP.NET Calendar Control.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Calendar ID="Calendar1" DayNameFormat="Full" runat="server">
<WeekendDayStyle BackColor="#fafad2" ForeColor="#ff0000" />
<DayHeaderStyle ForeColor="#0000ff" />
<TodayDayStyle BackColor="#00ff00" />
</asp:Calendar>
</div>
</form>
</body>
</html>Note:
- The Days in the ASP.NET Calendar control are displayed with Full names in Blue color.
DayNameFormat="Full"
<DayHeaderStyle ForeColor="#0000ff" />
- The Weekends in the ASP.NET Calendar control are displayed in Red Color in a Yellow Background.
<WeekendDayStyle BackColor="#fafad2" ForeColor="#ff0000" />
- The Current date in the ASP.NET Calendar Control is displayed with a green background.
<TodayDayStyle BackColor="#00ff00" />
The following are the Properties of the ASP.NET Calendar Control.
Property
|
Description
|
.NET
|
Caption
|
To specify the caption of the Calendar.
|
2.0
|
CaptionAlign
|
To specify Caption text’s alignment.
|
2.0
|
CellPadding
|
To specify cell walls and contents space in pixels (px).
|
1.0
|
CellSpacing
|
To specify cell space in pixels (px).
|
1.0
|
DayHeaderStyle
|
To define the styling for displaying the names of the days.
|
1.0
|
DayNameFormat
|
To define the format for displaying the names of the days.
|
1.0
|
DayStyle
|
To define styling for display days.
|
1.0
|
FirstDayOfWeek
|
Specifies the first day of the week.
|
1.0
|
NextMonthText
|
To declare the text for the Next Month hyperlink.
|
1.0
|
NextPrevFormat
|
To define the format of the Next and Previous month Links.
|
1.0
|
NextPrevStyle
|
To define the style for displaying Next and Previous month Links.
|
1.0
|
OtherMonthDayStyle
|
To specify the displaying style for the days not in the current month.
|
1.0
|
PrevMonthText
|
To specify the text to be displayed for the previous month link.
|
1.0
|
runat
|
To specify that the control is a server control i.e. must be set to “server”.
|
1.0
|
SelectedDate
|
To get the Selected Date.
|
1.0
|
SelectedDates
|
To get the Selected Dates.
|
1.0
|
SelectedDayStyle
|
To define the style for the Selected Days.
|
1.0
|
SelectionMode
|
To define how the user selects dates.
|
1.0
|
SelectMonthText
|
To declare the text displayed for the Month Selection Link.
|
1.0
|
SelectorStyle
|
To define the style for the Month and Weeks Selection Links.
|
1.0
|
SelectWeekText
|
To declare the text displayed for the Week Selection Link.
|
1.0
|
ShowDayHeader
|
To specify whether the Days of the Week should be shown or not. A Boolean Value is used.
|
1.0
|
ShowGridLines
|
To specify whether the Next and Previous Month Links should be shown or not. A Boolean Value is used.
|
1.0
|
ShowNextPrevMonth
|
To specify whether the Next and Previous Month Links should be shown or not. A Boolean Value is used.
|
1.0
|
ShowTitle
|
To specify whether the Title of the Calendar should be shown or not. A Boolean Value is used.
|
1.0
|
TitleFormat
|
To define the format for the Title of the Calendar.
|
1.0
|
TitleStyle
|
To specify the style for the Title of the Calendar.
|
1.0
|
TodayDayStyle
|
To specify the style for Today’s Date
|
1.0
|
TodaysDate
|
Specifies Today’s Date.
|
1.0
|
UseAccessibleHeader
|
To define whether to use the table header tag “<th>” element for the day headers instead of the table data tag “<td>” element.
|
2.0
|
VisibleDate
|
To declare the date that specifies that the month is currently visible in the Calendar.
|
1.0
|
WeekendDayStyle
|
To define the style for the Weekends.
|
1.0
|
OnDayRender
|
The function to be executed when Each Day Cell is created.
|
1.0
|
OnSelectionChanged
|
The function to be executed when the user selects a Day, Week or a Month.
|
1.0
|
OnVisibleMonthChanged
|
The function to be executed when the user navigates to a different Month.
|
1.0
|
In the following ASP.NET tutorial you will learn what an ASP.NET CheckBox Control is and how to use it and its properties.
The following is an ASP.NET tutorial on how to use an ASP.NET CheckBox Control.
ASP.NET CheckBox Control
The following are the Properties of the ASP.NET CheckBox Control.
| ||||||||||||||||||||||||||||||||||||
ASP.NET CheckBoxList Control is used to create a Check box group with multi selection options. Every selection option in the Check box group of the ASP.NET CheckBoxList Control is defined by using a ListItem Element.
Note:
- ASP.NET CheckBoxList Control can support Data Binding.
The following is an ASP.NET tutorial to help you learn how to use an ASP.NET CheckBoxList Control.
- Go to the Toolbox and under the Standard section, select CheckBoxList Control.
ASP.NET CheckBoxList Control
- Drag and drop it onto the Form area to declare it.
- The following is the code you get in the Source View.
<asp:CheckBoxList ID="CheckBoxList1" runat="server">
</asp:CheckBoxList>
- The following is shows an example use of the ASP.NET CheckBoxList Control.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:CheckBoxList id="checkbox1" AutoPostBack="True" TextAlign="Right" OnSelectedIndexChanged="Check" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:label id="message" runat="server"/>
</div>
</form>
</body>
</html>Note:
- Add one ASP.NET CheckBoxList control and an ASP.NET Label Control from the ToolBox on to the ASP.NET .aspx page.
- Create an event handler for the “SelectedIndexChanged” event by double clicking on the Checkbox. Next add the following code to the Code behind file (Default.aspx.vb)
Protected Sub Check(ByVal sender As Object, ByVal e As System.EventArgs) Handles checkbox1.SelectedIndexChanged
Dim i
message.Text = "<p>Selected Item(s):</p>"
For i = 0 To checkbox1.Items.Count - 1
If checkbox1.Items(i).Selected Then
message.Text += checkbox1.Items(i).Text + "<br />"
End If
Next
End SubNote:
- If one of the boxes is checked then the web page posts back to the server and the “Check” event is executed.
- The “SelectedIndexChanged” event handler “Check” is used to loop through the ASP.NET CheckBoxList control's Items collection and tests each item's Selected property.
- The selected items are then displayed in the ASP.NET Label Control.
The following are the Properties of the ASP.NET CheckBoxList Control.
Property
|
Description
|
.NET
|
CellPadding
|
To specify cell walls and contents space in pixels (px) between the border and the contents of the table cell.
|
1.0
|
CellSpacing
|
To specify cell space in pixels (px) between the table cells.
|
1.0
|
RepeatColumns
|
To define the number of columns to use for displaying the check box group.
|
1.0
|
RepeatDirection
|
To specify if the check box group is to be repeated horizontally or vertically.
|
1.0
|
RepeatLayout
|
To define the layout of the check box group.
|
1.0
|
runat
|
To specify that the control is a server control i.e. must be set to “server”.
|
1.0
|
TextAlign
|
To align the text next to the left or right of the Check Box.
|
1.0
|
ASP.NET DropDownList Control is used to create a Drop-down list with selectable items. Every selectable item in an ASP.NET DropDownList Control is defined by a ListItem Element.
Note:
- ASP.NET DropDownList Control can support Data Binding.
Now you will learn how to use the following ASP.NET tutorial on how to use an ASP.NET DropDownList Control.
- Go to the Toolbox and under the Standard section, select DropDownList Control.
ASP.NET DropDownList Control
- Drag and drop it onto the Form area to declare it.
- The following is the code you get in the Source View.
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
- The following is shows an example use of the ASP.NET DropDownList Control.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:DropDownList id="dropDownList1" runat="server">
<asp:ListItem>Item 1</asp:ListItem>
<asp:ListItem>Item 2</asp:ListItem>
<asp:ListItem>Item 3</asp:ListItem>
<asp:ListItem>Item 4</asp:ListItem>
<asp:ListItem>Item 5</asp:ListItem>
<asp:ListItem>Item 6</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" Text="Submit" OnClick="submit" runat="server"/>
<br />
<asp:label id="message" runat="server"/>
</div>
</form>
</body>
</html>Note:
- Add one ASP.NET DropDownList control, an ASP.NET Button Control and an ASP.NET Label Control from the ToolBox on to the ASP.NET .aspx page.
- Create an event handler for the “submit” event that is the Button Click event, by double clicking on the ASP.NET Button Control. Next add the following code to the Code behind file (Default.aspx.vb)
Protected Sub submit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
message.Text = "Selected Item: " & dropDownList1.SelectedItem.Text
End SubNote:
- If one of the drop down list is clicked and the submit button is pressed the web page posts back to the server and the “submit” event is executed.
- The “submit” event handler for the Button Click event is used to displays some text and the selected item, in a Label control.
The following are the Properties of the ASP.NET DropDownList Control.
Property
|
Description
|
.NET
|
SelectedIndex
|
To specify the Index of the item selected in the ASP.NET DropDownList Control.
|
1.0
|
OnSelectedIndexChanged
|
To define the name of the function to be executed if the index of the Selected item is changed.
|
1.0
|
runat
|
To specify that the control is a server control i.e. must be set to “server”.
|
1.0
|
No comments:
Post a Comment