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")
{
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:
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...";
}
}
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.