In the Blog Creating and Consuming Class Library in C#, Object Initializer I have demonstrated creating a simple Bank with Deposit and Withdraw functionality in Windows Forms.
Creating that in Windows Forms is straight forward.
When it comes to Web Forms (Asp .Net) you have to maintain sessions to get the same functionality.
Creating that in Windows Forms is straight forward.
When it comes to Web Forms (Asp .Net) you have to maintain sessions to get the same functionality.
int Balance = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowBal();
}
else
{
if (Session["Balance"] != null)
Balance = (int)Session["Balance"];
}
}
private void ShowBal()
{
lblCurBal.Text = Balance.ToString();
txtAmount.Text = "";
txtAmount.Focus();
}
protected void btnDeposit_Click(object sender, EventArgs e)
{
Balance += Int32.Parse(txtAmount.Text);
Session["Balance"] = Balance;
ShowBal();
}
protected void btnWithras_Click(object sender, EventArgs e)
{
Balance -= Int32.Parse(txtAmount.Text);
Session["Balance"] = Balance;
ShowBal();
}
.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<asp:Label ID="Label1" runat="server" Text="Balance"></asp:Label>
<asp:Label ID="lblCurBal" runat="server"></asp:Label>
<br />
<br />
<asp:Label ID="Label2" runat="server" Text="Amount"></asp:Label>
<asp:TextBox ID="txtAmount" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnDeposit" runat="server" OnClick="btnDeposit_Click" Text="Deposit" />
<asp:Button ID="btnWithras" runat="server" OnClick="btnWithras_Click" Text="Withdraw" />
</form>
</body>
</html>
Courtesy : Arjun Pandavath, Speridian Technologies
No comments:
Post a Comment