query strings

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jodiallbon
    New Member
    • May 2007
    • 6

    query strings

    Hi anyone..

    I am trying to complete a project for class and am a bit stuck.
    I have a login page, which when submitted goes to a members page.
    I want to take the primary key (CustID) from the login page (login Table) to the members page(Customers table), then use this primary key (CustID) to display data from the Customers Table in textboxes.
    I know how to display the data in the text boxes using a stored procedure, but
    I want the data to be already in these textboxes when the user gets to the members page.

    Hope this is not confusing..
    I have searched high and low for clues but cant seem to find any!!
    I am doing it in C# code in asp.net 1.1

    any clues/hints would be fantastic...

    Jodi
  • kenobewan
    Recognized Expert Specialist
    • Dec 2006
    • 4871

    #2
    Welcome to the site. So you want to post the primaryid to the second page and use that to query the member info?

    Comment

    • oohay251
      New Member
      • May 2007
      • 27

      #3
      your code to fill the text boxes should be placed in the .aspx pages Page_Load event procedure.

      Comment

      • jodiallbon
        New Member
        • May 2007
        • 6

        #4
        Originally posted by kenobewan
        Welcome to the site. So you want to post the primaryid to the second page and use that to query the member info?
        Hi there, yes thats exactly what I want to do.
        I think I nearly have it.. do you want me to show you my code??

        Comment

        • kenobewan
          Recognized Expert Specialist
          • Dec 2006
          • 4871

          #5
          Have a go and if you still have a problem post your code. Thanks.

          Comment

          • Nitinkcv
            New Member
            • Mar 2007
            • 65

            #6
            Originally posted by jodiallbon
            Hi there, yes thats exactly what I want to do.
            I think I nearly have it.. do you want me to show you my code??
            Hi,
            Have you been able to do the functionality.
            If not please post ur code so that we can have alook at it.

            Thanks

            Comment

            • jodiallbon
              New Member
              • May 2007
              • 6

              #7
              Originally posted by Nitinkcv
              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(objec t sender, System.EventArg s e)
              {

              if (!Page.IsPostBa ck)
              HyperLink1.Navi gateUrl = String.Format( "Register.aspx? ReturnURL={0}", Server.UrlEncod e( Request.QuerySt ring [ "ReturnURL" ] ) );
              }



              private void Button1_Click(o bject sender, System.EventArg s e)
              {
              int intResult = 0;
              string CustID = Request.QuerySt ring["CustID"];
              string hashedPassword = FormsAuthentica tion.HashPasswo rdForStoringInC onfigFile(txtPa ssword.Text,"MD 5");


              if (Page.IsValid)
              {
              // Set up Connection object
              SqlConnection SqlConnection1 = new SqlConnection() ;
              SqlConnection1. ConnectionStrin g=System.Config uration.Configu rationSettings. AppSettings["dsn"];

              // Set up Command object
              SqlCommand cmd1 = new SqlCommand();
              cmd1.Connection = SqlConnection1;
              cmd1.CommandTyp e = CommandType.Sto redProcedure;
              cmd1.CommandTex t = "procLogin" ;

              // Set up the Command object's parameters
              cmd1.Parameters .Add"@custid",S ystem.Data.SqlD bType.Int,4,"Cu stID");
              cmd1.Parameters["@custid"].Direction = ParameterDirect ion.Output;

              cmd1.Parameters .Add"@login",Sy stem.Data.SqlDb Type.VarChar,50 ,"CustLogin" );
              cmd1.Parameters["@login"].Direction = ParameterDirect ion.Input;
              cmd1.Parameters["@login"].Value = txtUsername.Tex t;

              cmd1.Parameters .Add("@password ", System.Data.Sql DbType.VarChar, 50,"CustPasswor d");
              cmd1.Parameters["@password"].Direction = ParameterDirect ion.Input;
              cmd1.Parameters["@password"].Value = hashedPassword;

              cmd1.Parameters .Add "@RETURN_VALUE" ,System.Data.Sq lDbType.Int,4, "RETURN_VALUE") ;
              cmd1.Parameters["@RETURN_VA LUE"].Direction =ParameterDirec tion.ReturnValu e;

              // Execute the command
              SqlConnection1. Open();
              cmd1.ExecuteNon Query();
              intResult = (int)cmd1.Param eters["@RETURN_VA LUE"].Value;
              SqlConnection1. Close();

              // Check and display error message
              switch (intResult)
              {
              case 0:
              // Both username & password ok
              System.Web.Secu rity.FormsAuthe ntication.Redir ectFromLoginPag e
              (txtUsername.Te xt, 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.Redire ct("Members/Members.aspx?Cu stID");

              }
              }


              Members Page:


              private void Page_Load(objec t sender, System.EventArg s e)
              {

              string Custid = (string)(Reques t.Params["CustID"]);
              HyperLink1.Navi gateUrl = String.Format( "UpdateProfile. aspx?ReturnURL= {0}", Server.UrlEncod e( Request.QuerySt ring [ "ReturnURL" ] ) );

              }



              UpdateProfilePa ge code:



              private void Page_Load(objec t sender, System.EventArg s e)
              {
              sqlConnection1. ConnectionStrin g=System.Config uration.Configu rationSettings. AppSettings["dsn"];

              string custid = (string)(Reques t.Params["CustID']);


              if(txtCustID.Te xt != String.Empty)
              {
              sqlCommand1.Par ameters["@custid"].Value=txtCustI D.Text;
              sqlConnection1. Open();
              sqlCommand1.Exe cuteNonQuery();

              if (sqlCommand1.Pa rameters["@login"].Value !=DBNull.Value)
              {
              txtUsername.Tex t = (string)sqlComm and1.Parameters["@login"].Value;
              txtPassword.Tex t = (string)sqlComm and1.Parameters["@password"].Value;
              txtName.Text = (string)sqlComm and1.Parameters["@name"].Value;
              txtStreet.Text = (string)sqlComm and1.Parameters["@street"].Value;
              txtPostcode.Tex t = sqlCommand1.Par ameters["@postcode"].Value.ToString ();
              txtState.Text = (string)sqlComm and1.Parameters["@state"].Value;
              txtPhone.Text = (string)sqlComm and1.Parameters["@phone"].Value;
              }
              }
              sqlConnection1. Close();

              }


              Thanks Jodi

              Comment

              • nmsreddi
                Contributor
                • Jul 2006
                • 366

                #8
                Hello

                i dint get why you are writing hyperlink navigate url in the page load section , try to avoid that ,you can use url property ofthe hyperlink if you want to navigate ,

                if you are navigating with in your application better use link buttons , write code in that click event

                hope you get the point

                Good Luck

                Comment

                • jodiallbon
                  New Member
                  • May 2007
                  • 6

                  #9
                  Originally posted by nmsreddi
                  Hello

                  i dint get why you are writing hyperlink navigate url in the page load section , try to avoid that ,you can use url property ofthe hyperlink if you want to navigate ,

                  if you are navigating with in your application better use link buttons , write code in that click event

                  hope you get the point

                  Good Luck

                  Hi thanks for your answer, but the problem Im having is that I need to pass the CustID to the Members.aspx page and then to the updateProfile.a spx
                  by query string, but I know my code must be wrong somewhere - any ideas??

                  Thanks Jodi

                  Comment

                  • Plater
                    Recognized Expert Expert
                    • Apr 2007
                    • 7872

                    #10
                    You should store that CustID in the Session object. Then you will not have to keep passing it from page to page in the URL.


                    LOGIN PAGE:
                    (person enters info, if correct a CustID is returned.)
                    (Put CustID in session, navigate to another page.)


                    (Whatever page uses it):
                    (In Page_Load() grab the CustID from the session, then run your stored procedure with it)

                    Comment

                    • lemuel
                      New Member
                      • May 2007
                      • 6

                      #11
                      i agree with plater that it's better to use sessions rather than querystrings for a custID which is a vital information...

                      anyway, you could do something like this on your login page:

                      Code:
                      private void btnSubmit_Click(object sender, System.EventArgs e)
                      {
                      Response.Redirect("Webform2.aspx?custID=" +
                      this.txtCustID.Text + ");
                      }
                      where Webform2.aspx is the web page where you want to be redirected and txtCustID.Text is the text box where the user enters his/her custID or you could also use a variable there instead.

                      and on your Webform2.aspx put this code in the page load event


                      Code:
                      private void Page_Load(object sender, System.EventArgs e)
                      {
                      this.txtBox1.Text = Request.QuearyString["custID"];
                      }
                      where txtBox1.Text is the control where you want your custID to showup.

                      hope i somehow helped :D

                      Comment

                      • jodiallbon
                        New Member
                        • May 2007
                        • 6

                        #12
                        Originally posted by Plater
                        You should store that CustID in the Session object. Then you will not have to keep passing it from page to page in the URL.


                        LOGIN PAGE:
                        (person enters info, if correct a CustID is returned.)
                        (Put CustID in session, navigate to another page.)


                        (Whatever page uses it):
                        (In Page_Load() grab the CustID from the session, then run your stored procedure with it)
                        thanks for that advice..I did it with session id and it works!!
                        yeah thanks

                        Comment

                        • jodiallbon
                          New Member
                          • May 2007
                          • 6

                          #13
                          Originally posted by lemuel
                          i agree with plater that it's better to use sessions rather than querystrings for a custID which is a vital information...

                          anyway, you could do something like this on your login page:

                          Code:
                          private void btnSubmit_Click(object sender, System.EventArgs e)
                          {
                          Response.Redirect("Webform2.aspx?custID=" +
                          this.txtCustID.Text + ");
                          }
                          where Webform2.aspx is the web page where you want to be redirected and txtCustID.Text is the text box where the user enters his/her custID or you could also use a variable there instead.

                          and on your Webform2.aspx put this code in the page load event


                          Code:
                          private void Page_Load(object sender, System.EventArgs e)
                          {
                          this.txtBox1.Text = Request.QuearyString["custID"];
                          }
                          where txtBox1.Text is the control where you want your custID to showup.

                          hope i somehow helped :D
                          thanks for that as well. You guys are really helpful on this site..
                          Thanks again.

                          Comment

                          Working...