Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

Q.7 Create a web page which will display banner and advertisements using AdRotat or Control.

<%@ Import Namespace="System.IO" %> <Script runat="Server"> Sub AdRotator_AdCreated( s As Object, e As AdCreatedEventArgs ) Dim intImpressions As Integer = 0 Dim strFileName As String Dim strmStreamReader As StreamReader Dim strmStreamWriter As StreamWriter ' Assign file name strFileName = e.AdProperties( "Campaign" ).Trim & ".imp" If strFileName = "" Then strFileName = "default.imp" End If ' Read current impressions If File.Exists( MapPath( strFileName ) ) Then strmStreamReader = File.OpenText( MapPath( strFileName ) ) intImpressions = Cint( strmStreamReader.ReadLine ) strmStreamReader.Close End If ' Write current impressions strmStreamWriter = File.CreateText( MapPath( strFileName ) ) strmStreamWriter.Write( intImpressions + 1 ) strmStreamWriter.Close End Sub </Script> <html> <head><title>AdRotatorImpressions.aspx</title></head> <body> <form Runat="Server"> <asp:AdRotator AdvertisementFile="AdCampaigns.xml" OnAdCreated="AdRotator_AdCreated" Runat="Server" /> </form> </body> </html>

Q.8 Create an interactive meeting scheduler using Calendar Control. <%@ <%@ <%@ <%@ Import Import Import Import Namespace="System.IO" %> Namespace="System.Runtime.Serialization" %> Namespace="System.Runtime.Serialization.Formatters.Binary" %> Namespace="System.Drawing" %>

<Script Runat="Server">

Dim arrCalendar( 13, 32 ) As String ' Get schedule from cache or disk Sub Page_Load Dim strmFileStream As FileStream Dim fmtrBinaryFormatter As BinaryFormatter If Cache( "arrCalendar" ) Is Nothing Then If File.Exists( "c:\schedule.bin" ) Then strmFileStream = _ New FileStream( "c:\schedule.bin", FileMode.Open ) fmtrBinaryFormatter = New BinaryFormatter arrCalendar = _ CType( fmtrBinaryFormatter.Deserialize( strmFileStream ), Array ) strmFileStream.Close() Cache( "arrCalendar" ) = arrCalendar End If Else arrCalendar = Cache( "arrCalendar" ) End If End Sub ' Save schedule to file Sub btnSave_Click( s As Object, e As EventArgs ) Dim dtmDate As DateTime Dim strmFileStream As FileStream Dim fmtrBinaryFormatter As BinaryFormatter dtmDate = calSchedule.SelectedDate arrCalendar( dtmDate.Month, dtmDate.Day ) = txtNotes.Text strmFileStream = _ New FileStream( "c:\schedule.bin", FileMode.Create ) fmtrBinaryFormatter = New BinaryFormatter fmtrBinaryFormatter.Serialize( strmFileStream, arrCalendar ) strmFileStream.Close() Cache( "arrCalendar" ) = arrCalendar End Sub ' Pick a date Sub Calendar_SelectionChanged( s As Object, e As EventArgs ) Dim dtmDate As DateTime dtmDate = calSchedule.SelectedDate txtNotes.Text = arrCalendar( dtmDate.Month, dtmDate.Day ) End Sub ' Display each calendar day Sub Calendar_RenderDay( s As Object, e As DayRenderEventArgs ) Dim dtmDate As DateTime Dim ctlCell As TableCell dtmDate = e.Day.Date ctlCell = e.Cell If arrCalendar( dtmDate.Month, dtmDate.Day ) <> "" Then ctlCell.BackColor = Color.FromName( "Orange" ) End If End Sub </Script>

<html> <head><title>CalendarSchedule.aspx</title></head> <body> <form Runat="Server"> <asp:Calendar id="calSchedule" Width="100%" ShowGridLines="True" OnSelectionChanged="Calendar_SelectionChanged" OnDayRender="Calendar_RenderDay" Runat="Server" /> <p> <asp:TextBox id="txtNotes" TextMode="MultiLIne" Columns="50" Rows="10" Runat="Server" /> <p> <asp:Button id="btnSave" Text="Save Changes" OnClick="btnSave_Click" Runat="Server" /> </form> </body> </html> Q.3 Validate the fields Email, Phone number and Entry Length of Registration For m created in question 2, using RegularExpressionValidator Control. VALIDATING EMAILS <Script Runat="Server"> Sub Button_Click( s As Object, e As EventArgs ) If IsValid Then Response.Redirect( "ThankYou.aspx" ) End If End Sub </Script> <html> <head><title>RegularExpressionvalidatorEmail.aspx</title></head> <body> <form Runat="Server"> Email Address: <br> <asp:TextBox id="txtEmail" Columns="50"

Runat="Server"/> <asp:RegularExpressionValidator ControlToValidate="txtEmail" Text="Invalid Email Address!" ValidationExpression="\S+@\S+\.\S{2,3}" Runat="Server" /> <p> <asp:Button Text="Submit" OnClick="Button_Click" Runat="Server"/> </form> </body> </html> VALIDATING PHONE NUMBERS <Script Runat="Server"> Sub Button_Click( s As Object, e As EventArgs ) If IsValid Then Response.Redirect( "ThankYou.aspx" ) End If End Sub </Script> <html> <head><title>RegularExpressionValidatorPhone.aspx</title></head> <body> <form Runat="Server"> Phone Number: <br> <asp:TextBox id="txtPhone" Columns="30" Runat="Server"/> <asp:RegularExpressionValidator ControlToValidate="txtPhone" Display="Dynamic" Text="Invalid Phone Number!" ValidationExpression="\(?\s*\d{3}\s*[\)\.\-]?\s*\d{3}\s*[\-\.]?\s*\d{4}" Runat="Server" /> <p> <asp:Button Text="Submit" OnClick="Button_Click" Runat="Server"/> </form> </body> </html>

VALIDATING ENTRY LENGTH <Script Runat="Server"> Sub Button_Click( s As Object, e As EventArgs ) If IsValid Then Response.Redirect( "ThankYou.aspx" ) End If End Sub </Script> <html> <head><title>RegularExpressionValidatorLength.aspx</title></head> <body> <form Runat="Server"> Enter your last name: <br>(no more than 10 characters) <br> <asp:TextBox id="txtLastname" Columns="50" Runat="Server"/> <asp:RegularExpressionValidator ControlToValidate="txtLastname" Display="Dynamic" Text="Your last name can contain a maximum of 10 characters and no spaces!" ValidationExpression="\S{0,10}" Runat="Server" /> <p> <asp:Button Text="Submit" OnClick="Button_Click" Runat="Server"/> </form> </body> </html> Q.4 Create a page which uses CompareValidator and RangeValidator Controls. <Script Runat="Server"> Sub Button_Click( s As Object, e As EventArgs ) If IsValid Then Response.Redirect( "Thankyou.aspx" ) End If End Sub </Script> <html> <head><title>CompareValidatorRange.aspx</title></head>

<body> <form Runat="Server"> Minimum Value: <asp:TextBox id="txtMinNumber" Runat="Server"/> <p> Maximum Value: <asp:TextBox id="txtMaxNumber" Runat="Server"/> <p> Value: <asp:TextBox id="txtRangeNumber" Runat="Server"/> <asp:CompareValidator ControlToValidate="txtRangeNumber" ControlToCompare="txtMinNumber" Display="Dynamic" Text="Number must be greater than minimum value!" Operator="GreaterThan" Type="Integer" Runat="Server" /> <asp:CompareValidator ControlToValidate="txtRangeNumber" ControlToCompare="txtMaxNumber" Display="Dynamic" Text="Number must be less than maximum value!" Operator="LessThan" Type="Integer" Runat="Server" /> <p> <asp:Button Text="Submit" OnClick="Button_Click" Runat="Server"/> </form> </body> </html>

You might also like