Reputation: 109
I know there have been a lot of questions regarding this subject but none seem to help me in my situation so I'm posting another.
I was given a project and asked to split the project out into separate controls. Originally there was a folder in the project called "events" that referenced a control called "EventsRssFeedControl". My boss asked me to separate the events and EventsRssFeedControl and put them together in their own project. So I did that. I changed all the namespaces and got everything to compile. But when I try to navigate there, I get an error. Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0120: An object reference is required for the non-static field, method, or property 'System.Web.UI.Control.Controls.get'
Source Error:
<input type="hidden" name="selectedDate" value="<%= UMNEventsRssFeedControl.Controls.UMNEventsRssFeedControl.SelectedDateStr %>"/>
My code looks like this and I'm confused by calling it "non-static" and more confused as to why it doesn't work.
private static string _selectedDateStr;
public static string SelectedDateStr
{
get { return _selectedDateStr; }
set { _selectedDateStr = value; }
}
It works in the old project and the only things changed were the namespaces and the calls to the new namespace.
Upvotes: 1
Views: 8264
Reputation: 31761
Your namespace and class are named the same thing. Don't do that.
Upvotes: 0
Reputation: 35594
The problem is actually not at SelectedDateStr
.
UMNEventsRssFeedControl.Controls
is asking for static getter of the property Controls
of UMNEventsRssFeedControl
. Obviously, Controls
is an instance property of the mentioned class.
You need to supply an instance of UMNEventsRssFeedControl
for the code to work.
Upvotes: 1