My project has a class ‘mybutton’.
namespace Project.WebUI.HtmlHelpers
{
public class myButton
{
public myButton()
{
Clickable = false;
Selected = false;
Url = "";
}
public myButton(string displayText, string url) : this()
{
DisplayText = displayText;
Url = url;
}
public bool Clickable { get; set; }
public bool Selected { get; set; }
public string DisplayText { get; set; }
public string Url { get; set; }
}
}
When I try to create a new instance of myButton from another class I get the error “A field initializer cannot reference the non-static field, method...” (red squiggle over url).
public class PageElements
{
url =”url goes here”;
public myButton CancelButton = new myButton("Cancel Order", url);
…
…
}
What am I doing wrong?
See Question&Answers more detail:os