first project

V

vinnie

i'm very new to asp.net-C# and since i want to learn it, i was just
trying to make this page to work, but i get an error message that says
"Error 1 The name 'US' does not exist in the current context C:\PATH-
TO-MY-PAGE\CurrencyConverter.aspx.cs 18 42"

These are the two files:

a) the aspx is:
<!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>Untitled Page</title>
</head>
<body>
<form id="form1" method="post" runat="server">
<div>

Convert&nbsp;<input id="US" type="text" />&nbsp;&nbsp;US
Dollar in Euro&nbsp;&nbsp;

<input id="Convert" type="submit" value="ok" /></div>
<div style="font-weight:bold"; ID="Result" runat="server">
</div>
</form>
<p>
&nbsp;</p>
</body>
</html>


b) the aspx.cs is:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;

public partial class CurrencyConverter : System.Web.UI.Page
{
protected void Convert_ServerClick(object sender, EventArgs e)
{
decimal USamount = decimal.Parse(US.Value);
decimal Euro = USamount * 1.30M;
Result.InnerText = USamount.ToString() + "US Dollars = ";
Result.InnerText += Euro.ToString() + "Euro ";
}
}


What's wrong?
 
V

vinnie

Try adding the runat="server" attribute to the tag for the US text box.

Brad

Thanks, i don't get any error now, however i don't see the results on
the screen: why?
 
B

Brad Wery

It worked for me...

Do you have an event handler setup for the button? You should see code
like this:

this.Convert.ServerClick += new
System.EventHandler(this.Convert_ServerClick);

I think with new version of ASP.NET this is placed in the html tag:

<input id="Convert" ... onserverclick="Convert_ServerClick">

I'm not sure if this is causing you a problem but, there is an extra
semi-colon in the code you pasted:

<div style="font-weight:bold"; ID="Result" runat="server">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top