2014-10-31 64 views
2

通過將我的按鈕設置爲可見,我遇到了問題。 我在MasterPage中創建了一些按鈕,並將其可見性設置爲false。 (button.Visible = false;) 按下按鈕後,我被重定向到另一個頁面。 在這個頁面上(一個來自MasterPage的孩子)我想設置一些可見的按鈕(Master.FindControl(「button」)。Visible = true),但這是我的問題。它沒有出現。ASP.NET可見= true並不顯示按鈕

MasterPage.master:

 <asp:Button ID="b_home" runat="server" Text="Home" CssClass="button" OnClick="b_home_Click"/> 
     <asp:Button ID="b_profil" runat="server" Text="Profil" CssClass="button" OnClick="b_profil_Click"/> 
     <asp:Button ID="b_reservieren" runat="server" Text="Reservieren" CssClass="button" OnClick="b_reservieren_Click"/> 
     <asp:Button ID="b_verleihhistorie" runat="server" Text="Verleihhistorie" CssClass="button" OnClick="b_verleihhistorie_Click"/> 
     <asp:Button ID="b_warenausgang" runat="server" Text="Warenausgang" CssClass="button" OnClick="b_warenausgang_Click"/> 
     <asp:Button ID="b_wareneingang" runat="server" Text="Wareneingang" CssClass="button" OnClick="b_wareneingang_Click"/> 
     <asp:Button ID="b_neueKunden" runat="server" Text="Neue Kunden" CssClass="button" OnClick="b_neueKunden_Click"/> 
     <asp:Button ID="b_kontakte" runat="server" Text="Kontakte" CssClass="button" OnClick="b_kontakte_Click"/> 
    </div> 

Master.master.cs

protected void Page_Load(object sender, EventArgs e) 
{ 
    b_home.Visible = true; 
    b_kontakte.Visible = true; 
    b_profil.Visible = false; 
    b_reservieren.Visible = false; 
    b_verleihhistorie.Visible = false; 
    b_warenausgang.Visible = false; 
    b_wareneingang.Visible = false; 
    b_neueKunden.Visible = false; 

} 

Default.aspx.cs

protected void Page_Load(object sender, EventArgs e) 
{ 


    if(MasterPage.istAngemeldet) 
    { 

     // .p = db.Persons.Where(s => s.Email==benutzername && s.Passwort== passwort).FirstOrDefault(); 


     l_willkommen.Text= "Herzlich Willkommen bei Bee-Coop.at, " + MasterPage.p.Vorname + "!"; 
     LinkButton l1 = (LinkButton)Master.FindControl("LinkButton1"); 
     l1.Text = "[Abmelden]"; 

     #region SideMenu_Control 

     switch(MasterPage.hatRolle) 
     { 
      case 0: Master.FindControl("b_home").Visible = true; 
        Master.FindControl("b_kontakte").Visible = true; 
        Master.FindControl("b_profil").Visible = true; 
        Master.FindControl("b_reservieren").Visible = true; 
        Master.FindControl("b_verleihhistorie").Visible = true; 
        Master.FindControl("b_warenausgang").Visible = true; 
        Master.FindControl("b_wareneingang").Visible = true; 
        Master.FindControl("b_neueKunden").Visible = true; 
        break; 

      case 1: Master.FindControl("b_home").Visible = true; 
        Master.FindControl("b_kontakte").Visible = true; 
        Master.FindControl("b_profil").Visible = true; 
        Master.FindControl("b_reservieren").Visible = true; 
        Master.FindControl("b_verleihhistorie").Visible = true; 
        Master.FindControl("b_warenausgang").Visible = true; 
        Master.FindControl("b_wareneingang").Visible = true; 
        break; 

      case 2: Master.FindControl("b_home").Visible = true; 
        Master.FindControl("b_kontakte").Visible = true; 
        Master.FindControl("b_profil").Visible = true; 
        Master.FindControl("b_reservieren").Visible = true; 
        Master.FindControl("b_verleihhistorie").Visible = true; 
        break; 

      case 3: Master.FindControl("b_home").Visible = true; 
        Master.FindControl("b_kontakte").Visible = true; 
        break;     
     } 

     #endregion 
    } 
} 
+0

的[面板可見=真沒有效果]可能重複(http://stackoverflow.com/questions/2539204/ panel-visible-true-no-effect) – 2014-10-31 12:24:39

+0

主頁面的Page_Load事件在頁面的Page_Load事件之後執行,這就是爲什麼會發生這種情況。 – 2014-10-31 14:38:42

回答

1

你每次一開始Page_Load事件頁面顯示,所以你的控件的可見性設置爲false,你需要我們的代碼更改爲:

protected void Page_Load(object sender, EventArgs e) 
{ 
      switch(MasterPage.hatRolle) 
    { 
     case 0: b_home.Visible = true; 
       b_kontakte.Visible = true; 
       b_profil.Visible = true; 
       b_reservieren.Visible = true; 
       b_verleihhistorie.Visible = true; 
       b_warenausgang.Visible = true; 
       b_wareneingang.Visible = true; 
       b_neueKunden.Visible = true; 
       break; 

     //case 1: ..... 
     //........... 
    } 
} 
0
protected void Page_Load(object sender, EventArgs e) 
{ 
    if (!Page.IsPostBack) 
    { 
     b_home.Visible = true; 
     b_kontakte.Visible = true; 
     b_profil.Visible = false; 
     b_reservieren.Visible = false; 
     b_verleihhistorie.Visible = false; 
     b_warenausgang.Visible = false; 
     b_wareneingang.Visible = false; 
     b_neueKunden.Visible = false; 
    } 
}