在两个母版页之间导航 [英] navigating between 2 master pages

查看:122
本文介绍了在两个母版页之间导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个有两种类型用户的应用程序,一个是admin和其他普通用户。我想为Admin和Normal用户创建2个单独的母版页。我也可以在两个母版页中使用相同的表格吗?



我正在处理的代码是:

 SqlConnection con =  new  SqlConnection( @ 数据源= ashish-pc; \\;初始目录= HMS;集成安全性=真); 
con.Open();
SqlCommand cmd = new SqlCommand( select *来自登录,其中UserName = @ UserName和密码= @密码,con);
cmd.Parameters.AddWithValue( @ UserName,UserName.Text.Trim() );
cmd.Parameters.AddWithValue( @ Password,Password.Text.Trim() );

SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = cmd;
// DataSet dt = new DataSet();
DataTable dt = < span class =code-keyword> new DataTable();
da.Fill(dt);
if (dt.Rows.Count> 0)
{
Session [ UserName] = UserName.Text;
Session.Timeout = 10 ;
if (dt.Rows [ 0 ] [ SuperUser]。ToString()== True
{
Response.Redirect( / Home.aspx);
}


else
{
Response.Redirect( / Appointment.aspx);

}


}
其他
{
Response.Write( 用户名和密码无效);
}
con.Close();
}





请帮我解决

解决方案

我的解决方案是不创建两个单独的主表单。在主主表单中创建嵌套主表单。然后你就可以使用基本主表格来反映所有的网页表格了。这个表格也是如此。



有关嵌套主表格的更多信息,请参考



http://www.asp.net/web-forms/ tutorials / master-pages / nested-master-pages-cs [ ^ ]



不需要移除代码块

I am working on a application which has 2 types of users, one is admin and other normal user. I want to create 2 separate master pages for Admin and Normal user. and also can i use same forms in both the master pages?

code i am working on is:

    SqlConnection con=new SqlConnection(@"Data Source=ashish-pc\;Initial Catalog=HMS;Integrated Security=True");
    con.Open();
    SqlCommand cmd = new SqlCommand("select * from Login where UserName=@UserName and Password=@Password", con);
    cmd.Parameters.AddWithValue("@UserName", UserName.Text.Trim() );
    cmd.Parameters.AddWithValue("@Password", Password.Text.Trim());

    SqlDataAdapter da = new SqlDataAdapter();
    da.SelectCommand = cmd;
   // DataSet dt = new DataSet();
    DataTable dt = new DataTable();
    da.Fill(dt);
    if (dt.Rows.Count>0)
    {
        Session["UserName"] = UserName.Text;
        Session.Timeout = 10;
        if (dt.Rows[0]["SuperUser"].ToString() == "True")
        {
            Response.Redirect("/Home.aspx");
        }


        else
        {
            Response.Redirect("/Appointment.aspx");

        }


    }
    else
    {
         Response.Write("Invalid username and password");
    }
    con.Close();
}



please help me out

解决方案

My solution is do not create two seperate master forms. Insted of this create nested master form inside main master form. Then you can use the base master form to all the web forms which in turn nested also comes into this case.

For more info on nested master form please refer

http://www.asp.net/web-forms/tutorials/master-pages/nested-master-pages-cs[^]

not necessary code block removed


这篇关于在两个母版页之间导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆