473,386 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

query strings

jodiallbon
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
May 26 '07 #1
12 1717
kenobewan
4,871 Expert 4TB
Welcome to the site. So you want to post the primaryid to the second page and use that to query the member info?
May 26 '07 #2
your code to fill the text boxes should be placed in the .aspx pages Page_Load event procedure.
May 26 '07 #3
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??
May 27 '07 #4
kenobewan
4,871 Expert 4TB
Have a go and if you still have a problem post your code. Thanks.
May 27 '07 #5
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
May 27 '07 #6
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
May 31 '07 #7
nmsreddi
366 256MB
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
May 31 '07 #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

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.aspx
by query string, but I know my code must be wrong somewhere - any ideas??

Thanks Jodi
May 31 '07 #9
Plater
7,872 Expert 4TB
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)
May 31 '07 #10
lemuel
6
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:

Expand|Select|Wrap|Line Numbers
  1. private void btnSubmit_Click(object sender, System.EventArgs e)
  2. {
  3. Response.Redirect("Webform2.aspx?custID=" +
  4. this.txtCustID.Text + ");
  5.  
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


Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3. this.txtBox1.Text = Request.QuearyString["custID"];
  4.  
where txtBox1.Text is the control where you want your custID to showup.

hope i somehow helped :D
Jun 1 '07 #11
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
Jun 1 '07 #12
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:

Expand|Select|Wrap|Line Numbers
  1. private void btnSubmit_Click(object sender, System.EventArgs e)
  2. {
  3. Response.Redirect("Webform2.aspx?custID=" +
  4. this.txtCustID.Text + ");
  5.  
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


Expand|Select|Wrap|Line Numbers
  1. private void Page_Load(object sender, System.EventArgs e)
  2. {
  3. this.txtBox1.Text = Request.QuearyString["custID"];
  4.  
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.
Jun 1 '07 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: theboss3 | last post by:
I am having trouble with accessing files with query strings. For example the code "require 'template.php?102932'" gives the following error: Warning: main(/www/blog/template.php?102932):...
4
by: Alistair | last post by:
I should just get a hat with a big D on it and then everyone would recognise me.. anyway... I have a DB full of people and their details.. I'm trying to perform a query based on age. so...
6
by: Martin Lacoste | last post by:
Ok, before I headbutt the computer... don't know why when I add criteria in a query, I get an 'invalid procedure call'. I also don't know why after searching the help in access, the various access...
2
by: Oliver Block | last post by:
Hello, sometimes one can see that on some site there are query strings appended to a URL even if the requested document is of .html form. What sense does that make? I couldn't find anything in...
30
by: Paul H | last post by:
I seem to end up with loads of append and update queries just because it's quick and easy to build queries or make a new ones based on an existing query. But I end up with loads of queries with...
12
by: zwasdl | last post by:
Hi, I'm using MS Access to query against Oracle DB via ODBC. Is it possible to use HINT in Access? Thanks, Wei
13
by: john | last post by:
I have table User-App and table App Profile User-App App Profile IDuser IDApp IDApp 1 34 34 1 45 45 2 34 2 45 2 90 3 34
3
by: Nathan Guill | last post by:
I have an interface that works with an Access back-end. I would like to store and/or load user defined query strings per each user (i.e. no user can access another's queries). The idea I had was...
17
by: NeoAlchemy | last post by:
I am starting to find more web pages that are using a query parameters after the JavaScript file. Example can be found at www.opensourcefood.com. Within the source you'll see: <script...
5
by: Just_a_fan | last post by:
I tried to put an "on error" statement in a routine and got the message that I cannot user "on error" and a lamda or query expression in the same routine. Help does not list anything useful for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.