簡體   English   中英

將值從母版頁上的隱藏字段轉換為子頁上的全局變量

[英]Getting the value from a hiddenfield on a Master page into a global variable on a Child page

我需要從母版頁上獲取隱藏字段的值,並將該值用作子頁上的全局變量。

我所做的就是將其放入“公共局部類”中:

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#不喜歡這樣,說“ A field initializer cannot reference the non-static field, method, or property 'Control.Page'

我將如何做這樣的事情?

這不是“全局”變量,而是類成員。 查看是否將其設為財產適合您:

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;
  }
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM