I have a user control named uc.ascx and an ASP.NET page named detail.aspx. Both of which are using codebehind, if it makes a difference.
In the aspx page I have the Register directive:
Code:
<%@ Register TagPrefix="Employees" TagName="uc" Src="uc.ascx" %>
and
Code:
<Employees:uc id="uc" Runat="server" />
In the user control, I have a dropdownlist named "MySelect", and in the codebehind, a string variable named "MySelectValue".
In the aspx page, I have a value that will determine the selected value of MySelect.
Here are some code snippets:
detail.aspx.cs:
Code:
private void Page_Load(object sender, System.EventArgs e) {
uc.MySelectValue = "SomeValue";
}
uc.ascx.cs:
Code:
public class uc : System.Web.UI.UserControl {
public System.Web.UI.WebControls.DropDownList MySelect;
public string MySelectValue {
get {return MySelect.SelectedValue;}
set {MySelect.SelectedValue = MySelectValue;}
}
}
When I build the solution, I receive a CS0120 error ("An object reference is required for the nonstatic field, method or property 'xxx.Employees.uc.MySelectValue'") on the 'uc.MySelectValue = "SomeValue";' line in detail.aspx.cs.
I've tried everything I can think of, and I am at a total loss. I just can't figure this one out.
Thanks for your help.