gpt4 book ai didi

c# - ASP.NET visible=true 不显示按钮

转载 作者:太空宇宙 更新时间:2023-11-03 13:15:10 24 4
gpt4 key购买 nike

我在将按钮设置为可见时遇到了问题。我在 MasterPage 中创建了一些按钮并将它们的可见性设置为 false。(button.Visible = false;)按下按钮后,我被重定向到另一个页面。在这个页面上(MasterPage 的一个 child )我想设置一些可见的按钮 (Master.FindControl("button").Visible=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
}
}

最佳答案

每次显示页面时都会启动 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: .....
//...........
}
}

关于c# - ASP.NET visible=true 不显示按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26674601/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com