Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
My Code in C#:
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;
                    }
                }
                
            }

        }


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:
C#
protected void btnLogin_Click(object sender, EventArgs e)
       {
           if (IsMatch() == true)
           {

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


For Cross Page Code is :
C#
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...";
            }
        }


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.
Posted
Updated 18-Jul-12 1:36am
v2
Comments
dimpledevani 18-Jul-12 7:31am    
Try using session to store your username and use it on our second form
sandeep nagabhairava 18-Jul-12 7:50am    
yahh!! i agree with you dimple...

1 solution

hi,

you can store values in session or can send via querystring.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900