[go: up one dir, main page]

0% found this document useful (0 votes)
71 views6 pages

Rich Server Control

The document describes several rich ASP.NET controls including the FileUpload, Calendar, AdRotator, and MultiView controls. The FileUpload control allows browsing and uploading files and storing them locally or in a database. The Calendar control allows selecting dates and customizing appearance. The AdRotator control displays random advertisements from an XML file or database. The MultiView control can divide a long form into multiple tabbed views.

Uploaded by

ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views6 pages

Rich Server Control

The document describes several rich ASP.NET controls including the FileUpload, Calendar, AdRotator, and MultiView controls. The FileUpload control allows browsing and uploading files and storing them locally or in a database. The Calendar control allows selecting dates and customizing appearance. The AdRotator control displays random advertisements from an XML file or database. The MultiView control can divide a long form into multiple tabbed views.

Uploaded by

ravi
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Rich Controls

ASP.NET provides large set of controls. These controls are divided into different categories,
depends upon their functionalities. The followings control comes under the rich controls category.
 FileUpload control
 Calendar control
 AdRotator control
 MultiView control

FileUpload control
FileUpload control is used to browse and upload files. After the file is uploaded, you can store the
file on any drive or database. FileUpload control is the combination of a browse button and a text
box for entering the filename.

The FileUpload control supports the following important properties.


 FileBytes: It returns the contents of uploaded file as a byte array
 FileContent: You can get the uploaded file contents as a stream.
 FileName: Provides the name of uploaded file.
 HasFile: It is a Boolean property that checks whether particular file is available or not.
 PostedFile: Gets the uploaded file wrapped in the HttpPostedFile object.

namespace file
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
if(IsPostBack)
{
string path = "D:\\ASP\\";
if(FileUpload1.HasFile)
{
string extention = System.IO.Path.GetExtension(FileUpload1.FileName).ToLower();
if(extention==".jpg")
{
Response.Write("Upload Success");
FileUpload1.SaveAs(path+FileUpload1.FileName);
}
else
{
Response.Write("Upload not success");
}
}
}
Calendar control
Calendar control provides you lots of property and events. By using these properties and events you
can perform the following task with calendar control.
 Select date.
 Selecting a day, a week or a month.
 Customize the calendar's appearance.

The Calendar control supports three important events:

Event Description
SelectionChanged This event is fired when you select a day, a week or an entire month.
DayRender This event is fired when each data cell of the calendar control is rendered.
VisibleMonthChanged It is raised when user changes a month.

Calendar control supports SelectionMode property that allows you to select a single day,
week, or entire month.
Example
using System;
using System.Text;
public partial class RichControl : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
Label1.Text ="Todays date is: "+ Calendar1.TodaysDate.ToShortDateString();
Label2.Text = "Your date of birth is: " + Calendar1.SelectedDate.ToShortDateString();
}
}
When you select a date, SelectionChanged event will fired and displays the date in a label
controls. In this example the date format is MM/DD/YYYY. Output:
AdRotator control
AdRotator control is used to display different advertisements randomly in a page. The list of
advertisements is stored in either an XML file or in a database table. Lots of websites uses
AdRotator control to display the advertisements on the web page.
To create an advertisement list, first add an XML file to your project.

Important properties of AdRotator control.


 ImageUrl: The URL of the image that will be displayed through AdRotator control.
 NavigateUrl: If the user clicks the banner or ad then the new page is opened according to
given URL.
 AlternateText: It is used for displaying text instead of the picture if picture is not displayed.
It is also used as a tooltip.
 Impressions: It is a number that sets how frequently an advertisement will appear.
 Keyword: It is used to filter ads or identifies a group of advertisement.

WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="ad.WebForm1" %>
<!DOCTYPE html>
<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" runat="server" AdvertisementFile="~/XMLFile1.xml" />
</div>
</form>
</body>
</html>
XMLFile1.xml
<?xml version="1.0" encoding="utf-8" ?>
<Advertisements>
<Ad>
<ImageUrl>~/Images/fileswap.gif</ImageUrl>
<NavigateUrl>http://www.fileswap.com</NavigateUrl>
<AlternateText>
Upload Files
</AlternateText>
<Impressions>20</Impressions>
<Keyword>Upload</Keyword>
</Ad>
<Ad>
<ImageUrl>~/Images/ssprw.gif</ImageUrl>
<NavigateUrl>http://www.speedysparrow.com</NavigateUrl>
<AlternateText>Host Website</AlternateText>
<Impressions>20</Impressions>
<Keyword>Host</Keyword>
</Ad>
</Advertisements>

MultiView control
MultiView control can be used when you want to create a tabbed page. In many situations, a web
form may be very long, and then you can divide a long form into multiple sub forms. MultiView
control is made up of multiple view controls. You can put multiple ASP.NET controls inside view
controls. One View control is displayed at a time and it is called as the active view. View control
does not work separately. It is always used with a Multiview control.

If working with Visual Studio 2010 or later, you can drag and drop a MultiView control onto the
form. You can drag and drop any number of View controls inside the MultiView control. The
number of view controls is depends upon the need of your application.

The MultiView control supports the following important properties


 ActiveViewIndex: It is used to determine which view will be active or visible.
 Views: It provides the collection of View controls contained in the MultiView control.

WebForm1.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="multi.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<h3>Multiview with 3 view</h3>
<asp:DropDownList ID="d1" OnSelectedIndexChanged="d1_SelectedIndexChanged"
runat="server" AutoPostBack="true">
<asp:ListItem Value="0">View 1</asp:ListItem>
<asp:ListItem Value="1">View 2</asp:ListItem>
<asp:ListItem Value="2">View 3</asp:ListItem>
</asp:DropDownList>

<asp:MultiView ID="m" ActiveViewIndex="0" runat="server">

<asp:View ID="v1" runat="server"><br /><br />


Now showing view 1<br /><br />
<asp:Calendar ID="c" runat="server"></asp:Calendar>
</asp:View>

<asp:View ID="v2" runat="server"><br /><br />


Now showing view 2<br /><br />
<asp:HyperLink ID="h" runat="server"
NavigateUrl="http://www.google.com">Link</asp:HyperLink>
</asp:View>

<asp:View ID="v3" runat="server"><br /><br />


Now showing view 3<br /><br />
<asp:TextBox ID="t1" runat="server" AutoPostBack="true"/><asp:RequiredFieldValidator
ID="RequiredFieldValidator1" runat="server" ErrorMessage="Field can not be empty"
ControlToValidate="t1"></asp:RequiredFieldValidator>
<asp:Button ID="b1" runat="server" Text="Check" />
</asp:View>

</asp:MultiView>
</div>
</form>
</body>
</html>

WebForm1.aspx.cs

using System.Web.UI.WebControls;
namespace multi
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void d1_SelectedIndexChanged(object sender, EventArgs e)
{
m.ActiveViewIndex = d1.SelectedIndex;
}
}
}

You might also like