Folks,
I am working through an ASP.NET book that focusses on vb.net. In order to learn better, I'm trying to convert the examples to C#.
Unfortunately, I've got stuck with event handling and can't find any reference I understand on the web.
The application is a currency converter (simple one!) that uses an aspx file and a cs file.
CS File code:
ASPX File code:
The example in VB.NET shows the following two lines which I do not know how to reproduce in c#:
and
I think I will need to use a delegate in c#, but am unure of what to do with it (you'll see I've declared one in my C# class).
Any advice would be greatly appreciated.
Thanks,
Graeme
website:
I am working through an ASP.NET book that focusses on vb.net. In order to learn better, I'm trying to convert the examples to C#.
Unfortunately, I've got stuck with event handling and can't find any reference I understand on the web.
The application is a currency converter (simple one!) that uses an aspx file and a cs file.
CS File code:
Code:
using Microsoft.VisualBasic;
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
public class CurrencyConverter : Page {
protected HtmlGenericControl Result;
protected HtmlInputButton Convert;
protected HtmlInputText US;
protected delegate void MyEvent();
private void Convert_ServerClick(Object sender, EventArgs e) {
decimal USAmount = Decimal.Parse(US.Value);
decimal EuroAmount = (USAmount * (decimal) 1.12);
Result.InnerText = USAmount.ToString() + " US Dollars = " + EuroAmount.ToString() + " Euros ";
}
}
ASPX File code:
Code:
<%@ Page Language="C#" Inherits="CurrencyConverter" Src="CurrencyConverter.cs" AutoEventWireup="False" %>
<html>
<body>
<form method="post" runat="server">
<div>
Convert:
<input type="text" id="US" runat="server" /> US Dollars to Euros.
<br /> <br />
<input type="submit" value="OK" id="Convert" runat="server" />
<div style="FONT_WEIGHT: bold" id="Result" runat="server"></div>
</div>
</form>
</body>
</html>
The example in VB.NET shows the following two lines which I do not know how to reproduce in c#:
Code:
' It's the WithEvents keyword throwing me here
Protected WithEvents Convert as HtmlInputButton
Code:
' it's the handles keyword throwing me here!
Private Sub Convert_ServerClick(blah) Handles Convert.ServerClick
Any advice would be greatly appreciated.
Thanks,
Graeme
website: