我有我的母版頁菜單和標籤,我想這取決於用戶登錄的類型進行更新。刪除菜單中的特定項目並通過asp.net中的內容頁面替換新菜單?
首先我刪除從菜單中工作正常,但它沒有顯示在主可達幾的MenuItems頁。相反,只有有限用戶才能看到所有菜單項的舊菜單。當我調試標籤文本顯示我已經設置,但當頁面加載它不更新。
正在使用以下代碼。
Label lbWelcomeMessage = new Label();
protected void Page_Load(object sender, EventArgs e)
{
Master.FindControl("CAMenu").Visible = false;
}
protected void btnLogin_Click(object sender, EventArgs e)
{
string userName = txtUsername.Text;
string password = txtPassword.Text;
Common common = new Common();
DataTable tab = new DataTable();
tab= common.GetUserDetails(userName);
string firstName = string.Empty;
string userPassword = string.Empty;
string RoleID=string.Empty;
if (tab.Rows.Count == 1)
{
firstName = tab.Rows[0][2].ToString();
userPassword = tab.Rows[0][4].ToString();
RoleID = tab.Rows[0][5].ToString();
}
if (userPassword == password)
{
if (RoleID != "1")
{
Menu CAMenu = new Menu();
CAMenu = (Menu)Master.FindControl("CAMenu");
int count = CAMenu.Items.Count;
for (int i = 3; i > 0; i--)
{
string text = CAMenu.Items[i - 1].Text;
CAMenu.Items.RemoveAt(i - 1);
}
lbWelcomeMessage = (Label)Master.FindControl("lbLoginMessage");
lbWelcomeMessage.Text = "Welcome"+" "+ firstName;
((SiteMaster)Page.Master).MyText = lbWelcomeMessage.Text;
Response.Redirect("AdHocSMS.aspx");
}
else
{
lbWelcomeMessage = (Label)Master.FindControl("lbLoginMessage");
lbWelcomeMessage.Text = lbWelcomeMessage.Text+" "+firstName ;
Response.Redirect("NewTemplate.aspx");
}
}
}
這是剛剛進入無限循環..做你認爲我需要做出任何改變? – Apoorva 2012-04-22 07:28:39
thnx這個偉大的答案。它不完全爲我工作,但我用你的答案的東西,現在我的代碼運作良好:) Thnx噸... – Apoorva 2012-04-22 13:28:35
我很高興它幫助。如果你可以編輯你的文章,並在你的問題後發佈你的解決方案,這將是非常好的,所以其他開發人員可以從你的一些指點:) – 2012-04-23 08:02:43