OK, so I’m using Mono on Mac OS X to work simple “applications” using ASP.NET and C# and I’m having two issues with my code.
Here is my Default.aspx presentation markup:
<%@ Page Language="C#" Inherits="project1.Tree" %>
<!DOCTYPE html>
<html>
<head runat="server">
<title>project1_test</title>
</head>
<body>
<form runat="server">
<asp:HiddenField id="hd_Height" runat="server" />
<p><asp:label runat="server" id="lblOutput" /></p>
<asp:TextBox ID="txtGrowBy" runat="server" />
<asp:Button id="btnGrow" runat="server" Text="Grow!!!" />
</form>
</body>
</html>
And here is my CodeBehind C# file:
using System;
using System.Web;
using System.Web.UI;
namespace project1
{
public partial class Tree : System.Web.UI.Page
{
private void PersistHeight(int height)
{
this.Session["height"] = height;
}
private int RestoreHeight()
{
return (int)this.Session[0];
}
public int Height
{
get
{
return int.Parse(hd_Height.Value).ToString();
}
set
{
hd_Height.Value = value.ToString();
}
}
public int height = 0;
public void Grow(int heightToGrow) {
height += heightToGrow;
}
protected void Page_Load(Object Source, EventArgs E)
{
string msg = "Let's plant a tree!<br/>";
msg += "I've created a tree with a height of " +
this.height + " metres.<br/>";
lblOutput.Text = msg;
}
public virtual void btnGrowClicked (object sender, EventArgs args)
{
txtGrowBy.Text = this.heightToGrow;
}
}
}
Mono gives me the following two errors:
1) cannot implicitly convert type 'string' to 'int'
line return int.Parse(hd_Height.Value).ToString();
2) Type 'project1.Tree' does not contain a definition for 'heightToGrow' and no extension method 'heightToGrow' of type 'project1.Tree could be found
line txtGrowBy.Text = this.heightToGrow;
For 1: Height is int, you can’t return a string in it’s get.
For 2: HeightToGrow is not a field or property of your class, so you can’t use it like that.
I’m not sure what you were trying to achieve in 2, but you may want to call
Grow, and then get the tree’s height.