跨页发布回ASP.NET [英] Cross Page Post back in ASP.NET

查看:72
本文介绍了跨页发布回ASP.NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

我正在使用登录页面(不使用登录视图控件),并且想要在下一页中显示用户名.

在下一页中,我使用标签来显示用户名.

下面是代码.

Dear All,

I am using a login page (not using the Login View Control) and want to display the user name in the Next Page.

In the Next Page I am using a label to display the User name.

Below is the Code.

public partial class Login : System.Web.UI.Page
{
   public string UserName
   {
    get
   {
       return (string)ViewState["login_name"];
    }
       set
       {
           ViewState["login_name"] = TextBox1.Text;
       }
   }

    protected void Page_Load(object sender, EventArgs e)
    {
        
    }
    

    protected void Button1_Click(object sender, EventArgs e)
    {

        if ((RequiredFieldValidator1.IsValid) && (RequiredFieldValidator2.IsValid))
        {
            

            using (DataTable dt = LookupUser(TextBox1.Text))
            {
                if (dt.Rows.Count != 0)
                {
                   
                    string dbPassword = Convert.ToString(dt.Rows[0]["password"]);
                    string appPassword = TextBox2.Text;
                    if (string.Compare(dbPassword, appPassword) == 0)
                    {
                        
                        Response.Redirect("~/QuizTopics.aspx");
                    }
                    else
                    {
                        Response.Write("Invalid Password");
                    }
                
                }
                else
                {
                    Response.Redirect("~/Login.aspx");
                    
                    Response.Write("The User name is incorrect");
                }
            }
        }
        else
        {
            Response.Redirect("~/Login.aspx");
            Response.Write("Please do not leave the fields blank");
        }
            


        }
    }




这是下一页的代码.




This is the code for the Next Page.

protected void Page_Load(object sender, EventArgs e)
    {
        if (PreviousPage != null)
        {
            Login loginpage = PreviousPage as Login;
            if (loginpage != null)
            {
                //uname is the ID of the Label Control.
                uname.Text = loginpage.UserName;
 
            }
        }



请协助....

问候

MK



Kindly assist....

Regards

MK

推荐答案

为什么要尝试/保持仅限于一页的用户名并使用PreviousPage进行访问?这是一种Profile对象值,您应该将其保留在会话中,并在所有页面上对其进行访问.

除了欢迎页面,您将/应该在所有页面中显示用户名.

此外,仅出于参考目的,请查看此文章 [链接 [
Why to try/keep username limited to only one page and use PreviousPage to access it? It''s kind of Profile object value, you should keep this in a session and access it across all the pages.

Apart from welcome page, you would/should show the username in all the pages.

Further, just for information sake, have a look at this article [^]for how/when to use PreviousPage property. One more link[^].


这篇关于跨页发布回ASP.NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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