Hi,
Have you been able to do the functionality.
If not please post ur code so that we can have alook at it.
Thanks
Hi no still no luck - Im know Im doing something wrong with passing the ID.
This is what I want to do:
Click on members link to go to a members page. This link redirects to the login page, so once logged in goes to Members page which has hyperlink to update profile page. So I need to pass the CustID from the login page to the members page and then to the update profiles page, where once opened displays all the customers details in the text boxes already.
I have the stored procedure for the display profile done, and this will be called on page load. Just need to work out how to pass the CustID.
Hope thats not confusing.
I shall give you the code for all 3 pages. Some code is hard coded and the some not.
Login Page code:
private void Page_Load(object sender, System.EventArgs e)
{
if (!Page.IsPostBack)
HyperLink1.NavigateUrl = String.Format( "Register.aspx?ReturnURL={0}", Server.UrlEncode( Request.QueryString [ "ReturnURL" ] ) );
}
private void Button1_Click(object sender, System.EventArgs e)
{
int intResult = 0;
string CustID = Request.QueryString["CustID"];
string hashedPassword = FormsAuthentication.HashPasswordForStoringInConfig File(txtPassword.Text,"MD5");
if (Page.IsValid)
{
// Set up Connection object
SqlConnection SqlConnection1 = new SqlConnection();
SqlConnection1.ConnectionString=System.Configurati on.ConfigurationSettings.AppSettings["dsn"];
// Set up Command object
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = SqlConnection1;
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.CommandText = "procLogin";
// Set up the Command object's parameters
cmd1.Parameters.Add"@custid",System.Data.SqlDbType .Int,4,"CustID");
cmd1.Parameters["@custid"].Direction = ParameterDirection.Output;
cmd1.Parameters.Add"@login",System.Data.SqlDbType. VarChar,50,"CustLogin");
cmd1.Parameters["@login"].Direction = ParameterDirection.Input;
cmd1.Parameters["@login"].Value = txtUsername.Text;
cmd1.Parameters.Add("@password", System.Data.SqlDbType.VarChar,50,"CustPassword");
cmd1.Parameters["@password"].Direction = ParameterDirection.Input;
cmd1.Parameters["@password"].Value = hashedPassword;
cmd1.Parameters.Add "@RETURN_VALUE",System.Data.SqlDbType.Int,4, "RETURN_VALUE");
cmd1.Parameters["@RETURN_VALUE"].Direction =ParameterDirection.ReturnValue;
// Execute the command
SqlConnection1.Open();
cmd1.ExecuteNonQuery();
intResult = (int)cmd1.Parameters["@RETURN_VALUE"].Value;
SqlConnection1.Close();
// Check and display error message
switch (intResult)
{
case 0:
// Both username & password ok
System.Web.Security.FormsAuthentication.RedirectFr omLoginPage
(txtUsername.Text, false);
break;
case 1:
// Username ok but not password
Label1.Text = "Invalid Password";
break;
case 2:
// Username does not exist
Label1.Text = "Invalid Username";
break;
}
Response.Redirect("Members/Members.aspx?CustID");
}
}
Members Page:
private void Page_Load(object sender, System.EventArgs e)
{
string Custid = (string)(Request.Params["CustID"]);
HyperLink1.NavigateUrl = String.Format( "UpdateProfile.aspx?ReturnURL={0}", Server.UrlEncode( Request.QueryString [ "ReturnURL" ] ) );
}
UpdateProfilePage code:
private void Page_Load(object sender, System.EventArgs e)
{
sqlConnection1.ConnectionString=System.Configurati on.ConfigurationSettings.AppSettings["dsn"];
string custid = (string)(Request.Params["CustID']);
if(txtCustID.Text != String.Empty)
{
sqlCommand1.Parameters["@custid"].Value=txtCustID.Text;
sqlConnection1.Open();
sqlCommand1.ExecuteNonQuery();
if (sqlCommand1.Parameters["@login"].Value !=DBNull.Value)
{
txtUsername.Text = (string)sqlCommand1.Parameters["@login"].Value;
txtPassword.Text = (string)sqlCommand1.Parameters["@password"].Value;
txtName.Text = (string)sqlCommand1.Parameters["@name"].Value;
txtStreet.Text = (string)sqlCommand1.Parameters["@street"].Value;
txtPostcode.Text = sqlCommand1.Parameters["@postcode"].Value.ToString();
txtState.Text = (string)sqlCommand1.Parameters["@state"].Value;
txtPhone.Text = (string)sqlCommand1.Parameters["@phone"].Value;
}
}
sqlConnection1.Close();
}
Thanks Jodi