我有一个登录页面,后面的代码如下:
protected void btnLog_Click(object sender, EventArgs e)
{
SqlConnection conn1 = new SqlConnection("Data Source=GATE-PC\\SQLEXPRESS;Initial Catalog=dbUsers;Integrated Security=True");
conn1.Open();
SqlCommand cmdd = new SqlCommand("select * from Users where UserName = @user AND Password = @pass", conn1);
SqlParameter param = new SqlParameter();
SqlParameter param1 = new SqlParameter();
param.ParameterName = "@user";
param1.ParameterName = "@pass";
param.Value = txtuser.Text;
param1.Value = txtpass.Text;
cmdd.Parameters.Add(param);
cmdd.Parameters.Add(param1);
SqlDataReader reader = cmdd.ExecuteReader();
if (reader.HasRows)
{
reader.Read();
MessageBox("Login Successful");
clear();
}
else
{
MessageBox("Invalid Username/Password");
}
}
我有两个站点地图:
<asp:Menu ID="NavigationMenu" runat="server" CssClass="menu"
EnableViewState="False" IncludeStyleBlock="False" Orientation="Horizontal"
DataSourceID="SiteMapDataSource1" StaticDisplayLevels="2"
onmenuitemdatabound="NavigationMenu_MenuItemDataBound">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource1" runat="server" />
<div class="clear hideSkiplink">
<asp:Menu ID="Menu1" runat="server" CssClass="menu"
EnableViewState="False" IncludeStyleBlock="False" Orientation="Horizontal"
DataSourceID="SiteMapDataSource2" StaticDisplayLevels="2"
onmenuitemdatabound="NavigationMenu_MenuItemDataBound">
</asp:Menu>
<asp:SiteMapDataSource ID="SiteMapDataSource2" runat="server" SiteMapProvider="AdminSiteMapProvider"/>
我想要实现的是当用户未登录时 Menu1 将显示并且 NavigationMenu 将隐藏但如果用户登录 Menu1 将隐藏然后 NavigationMenu 将显示。
我正在使用带有 C# 的 asp.net。