将数据从一页发送到另一页 [英] Send data from 1 page to another page

查看:81
本文介绍了将数据从一页发送到另一页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在C#中的代码:

My Code in C#:

private bool IsMatch()
        {
            if (drpCategory.Text.ToString() == "<< Select Category >>")
            {
                lblLogin.Visible = true;
                lblLogin.Text = "Please select category from (Login Category) list";
                return false;
            }
            else
            {
                if (drpCategory.SelectedIndex == 1)
                {
                    try
                    {
                        db.Adapter("select COUNT(UserName) from tblLogin where UserName = '" + txtUserName.Text.ToString() + "' and Password ='" + txtPassword.Text.ToString() + "'", "student");
                        if (db.dataSet.Tables["student"].Rows[0][0].ToString() == "1")
                        {
                           // btnLogin.PostBackUrl = "~/UploadJournal.aspx";
                            return true;
                            
                        }
                        else
                        {
                            lblLogin.Visible = true;
                            lblLogin.Text = "Please correct your User Name or Password...";
                            return false;
                        }
                    }
                    catch (Exception ex)
                    {
                        lblLogin.Visible = true;
                        lblLogin.Text = ex.Message.ToString();
                        return false;
                    }
                }

                else if (drpCategory.SelectedIndex == 2)
                {
                    if (txtUserName.Text.ToString() == "teacher" && txtPassword.Text.ToString() == "teacher")
                        return true;
                    else
                    {
                        lblLogin.Visible = true;
                        lblLogin.Text = "Please correct your User Name or Password...";
                        return false;
                    }
                }
                else
                {
                    if (txtUserName.Text.ToString() == "admin" && txtPassword.Text.ToString() == "admin")
                        return true;
                    else
                    {
                        lblLogin.Visible = true;
                        lblLogin.Text = "Please correct your User Name or Password...";
                        return false;
                    }
                }
                
            }

        }



这是IsMatch()方法,该方法从MS-SQL-2005搜索用户名和密码,如果它与userName相匹配,并从TextBox1和TextBox2的值中相应地输入passWord,则它将使用userName的值打开另一个页面.它发生了,但是,我必须输入两次密码.就像我在TextBox2的密码字段中输入"password"并单击登录"按钮时一样,它没有打开DefaultPage2.aspx只是清除了TextBox2的字段,而不是我再次打开密码而不是其打开DefaultPage2.aspx.

我的问题是为什么我应该输入两次登录密码?

我的Button_Click事件为:



This is IsMatch() methods which search username and password from MS-SQL-2005 and if it match the userName and passWord accordingly from TextBox1 and TextBox2''s value than it open another page with the value of userName. Its happening but, I have to put password two times. Like as when I am putting "password" in password field on TextBox2 and click in Login-button then it''s not opening DefaultPage2.aspx just clearing TextBox2''s field than I am putting password again than its opening DefaultPage2.aspx.

My question is why should I put two times password for login ?

My Button_Click Event is:

protected void btnLogin_Click(object sender, EventArgs e)
       {
           if (IsMatch() == true)
           {

               btnLogin.PostBackUrl = "~/UploadJournal.aspx";
           }
       }



跨页代码为:



For Cross Page Code is :

protected void Page_Load(object sender, EventArgs e)
        {
            if (Page.PreviousPage != null && PreviousPage.IsCrossPagePostBack)
            {
                TextBox SourceTextBox = (TextBox)Page.PreviousPage.FindControl("txtUserName");
                if (SourceTextBox != null)
                {
                    lblUserName.Text = SourceTextBox.Text.ToString();
                }
            }
            else
            {
                lblUserName.Text = "Trying...";
            }
        }



现在,如果用户名和密码首先匹配,请在另一页中发送用户名,以帮助我.我没有在属性窗口中设置登录按钮的PostBackUrl属性,这是因为它不匹配任何用户名和密码,它只是直接打开目标页面.



Now, please help me by sending username in another page if the username and password is match first. I am not setting PostBackUrl properties of login-button in properties window cause than this not matching anything username and password it just opening target-page directly.

推荐答案

hi,

您可以将值存储在会话中,也可以通过查询字符串发送.


you can store values in session or can send via querystring.


这篇关于将数据从一页发送到另一页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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