Reputation: 8402
I need to grab the value of a hidden field from a Master page and use the value as a global variable on a child page.
What I did was put this into the Public Partial Class:
public partial class frmBenefitSummaryList : System.Web.UI.Page
{
//public string PlanID = Convert.ToString(Request.QueryString["PlanID"]);
//public string AuditID = Convert.ToString(Request.QueryString["AuditID"]);
//public string UID = LoginSecurity.GetUser("ID");
public string SecLevel = (HiddenField)Page.Master.FindControl("hdnSecLevel");
C# doesn't like this, says "A field initializer cannot reference the non-static field, method, or property 'Control.Page'
"
How would I go about doing something like this?
Upvotes: 0
Views: 212
Reputation: 15893
This is not a "global" variable, but a class member. See if making it a property works for you:
private HiddenField secLevelField = null;
public string SecLevel {
get
{
if (secLevelField == null)
secLevelField = (HiddenField)Page.Master.FindControl("hdnSecLevel");
if (secLevelField != null)
return secLevelField.Value;
else
return null;
}
}
Upvotes: 2