For this assignment we use a master page, and on the first page did an Ajax panel. Ajax allows for a section to be updated rather than the whole page as usual. .Net makes Ajax easy. You add a script manager to the page, add an update panel, and then put your controls within them.
The other main point of the assignment was the consuming of web services. First locate a Web service then go to WebSite/Add Web Service. Paste the web service URL into the text box, give the service a name and add the service. Now you can treat it as a class in your program.
Master Page code
<%@ Master Language="C#" AutoEventWireup="true"
CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
<!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>
<asp:ContentPlaceHolder id="head" runat="server">
</asp:ContentPlaceHolder>
<link href="StyleSheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<h1>Service Examples</h1>
<p>
<asp:LinkButton ID="LinkButton1" runat="server"
onclick="LinkButton1_Click">Mortgage</asp:LinkButton> </p>
<div>
<asp:ContentPlaceHolder id="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</form>
</body>
</html>
here is the code behind the Master page
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class MasterPage : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("Default2.aspx");
}
}
Here is the source for default one which has the ajax and the weather web service
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<h2>First Page</h2>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<p>
<asp:Label ID="Label1" runat="server" Text="Enter City Name"></asp:Label>
<asp:TextBox ID="txtCity" runat="server"></asp:TextBox></p>
<p>
<asp:Label ID="Label2" runat="server" Text="Enter Country Name"></asp:Label>
<asp:TextBox ID="txtCountry" runat="server"></asp:TextBox></p>
<asp:Button ID="Button1" runat="server" Text="Get Weather"
onclick="Button1_Click" />
<asp:Label ID="lblWeather" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
</asp:Content>
Here is the code behind Default.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using net.webservicex.www;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
GlobalWeather gw = new GlobalWeather();
string weather = gw.GetWeather(txtCity.Text, txtCountry.Text);
lblWeather.Text = weather;
}
}
here is the source for default2.aspx
<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master"
AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
<p> <asp:Label ID="Label1" runat="server" Text="Years"></asp:Label>
<asp:TextBox ID="txtYears" runat="server"></asp:TextBox></p>
<p><asp:Label ID="Label2" runat="server" Text="Interest"></asp:Label>
<asp:TextBox ID="txtInterest" runat="server"></asp:TextBox></p>
<p><asp:Label ID="Label3" runat="server" Text="LoanAmount"></asp:Label>
<asp:TextBox ID="txtLoanAmount" runat="server"></asp:TextBox></p>
<p><asp:Label ID="Label4" runat="server" Text="Annual Tax"></asp:Label>
<asp:TextBox ID="txtTax" runat="server"></asp:TextBox></p>
<p><asp:Label ID="Label5" runat="server" Text="Insurance"></asp:Label>
<asp:TextBox ID="txtInsurance" runat="server"></asp:TextBox></p>
<asp:Button ID="Button1" runat="server" Text="Get Mortage"
onclick="Button1_Click" />
<hr />
<p>
<asp:Label ID="lblPandI" runat="server" Text="Label"></asp:Label> </p>
<p> <asp:Label ID="lblTax" runat="server" Text="Label"></asp:Label> </p>
<p> <asp:Label ID="lblInsurance" runat="server" Text="Label"></asp:Label> </p>
<p> <asp:Label ID="lblTotal" runat="server" Text="Label"></asp:Label> </p>
</asp:Content>
Here is the code behind Default1.aspx
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using net.mortgageinfo.www;
using System.Data;
using System.Xml;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Mortgage m = new Mortgage();
int years = int.Parse(txtYears.Text);
double interest=double.Parse(txtInterest.Text);
double loan=double.Parse(txtLoanAmount.Text);
double tax = double.Parse(txtTax.Text);
double insurance=double.Parse(txtInsurance.Text);
MortgageResults mr = m.GetMortgagePayment(years, interest, loan, tax, insurance);
lblPandI.Text = mr.MonthlyPrincipalAndInterest.ToString("c");
lblInsurance.Text = mr.MonthlyInsurance.ToString("c");
lblTax.Text = mr.MonthlyTax.ToString("c");
lblTotal.Text = mr.TotalPayment.ToString("c");
}
}
Here is the style sheet, such as it is
body {
}
h1
{
background-color:Navy;
color:White;
height:40px;
text-align:center;
}