473,326 Members | 2,192 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,326 software developers and data experts.

Can't get querystring to post to second page

I've got a c# script whereas I am trying to post from a textbox on my
firstpage.aspx over to page2.aspx, but the error I get is:The name
'txtstuff' does not exist in the class or namespace 'ASP.page2_aspx'
firstpage.aspx button object subroutine:
///////////////////////
private void btnSubmit_Click(object sender, System.EventArgs e)
{
Response.Redirect("dg4.aspx?txtboarddate=" +
this.txtboarddate.Text);
}
///////////////////////
page2.aspx script:
//////////////////////////////////////////
<%@ Import Namespace="System.Data"%>

<%@ Import Namespace="System.Data.SqlClient"%>

<script Language="C#" runat="server">

private void Page_Load(object sender, System.EventArgs e)

{

txtstuff = Request.QueryString["txtstuff"];

if(txtstuff != null){

if(txtstuff =="") txtstuff = "Visitor";

}

////txtstuff = Request.QueryString["txtstuff "];

////this.txtstuff .Text = Request.QueryString["txtstuff "];

BindMe();

}

// function to bind the records retrieved

// from the database to "dgrid" grid

void BindMe() {

////

string txtstuff = Request.QueryString["txtstuff"];

// build the connection string

string strConn = "SERVER=xxx.xx.xx.xx;UID=xxx;PWD=xxxx;DATABASE=myd b;";


// connect to the database

SqlConnection objConn = new SqlConnection(strConn);
// query

string strSQL = "SELECT * FROM tblDb where MyDate = '" & txtstuff &
"'";

// create an instance of the DataReader object

SqlCommand objCommand = new SqlCommand(strSQL, objConn);

objConn.Open();

SqlDataReader objReader = objCommand.ExecuteReader();
// assign the DataReader object as the source

// for the "dgrid" grid

dgrid.DataSource = objReader;

dgrid.DataBind();

// free up memory

objReader.Close();

objConn.Close();

}

</script>
???????????????
chumley

Nov 19 '05 #1
6 1183
You never declared the variable 'txtstuff'. You just tried to assign it a
value.

"Chumley Walrus" <sp*******@yahoo.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
I've got a c# script whereas I am trying to post from a textbox on my
firstpage.aspx over to page2.aspx, but the error I get is:The name
'txtstuff' does not exist in the class or namespace 'ASP.page2_aspx'
firstpage.aspx button object subroutine:
///////////////////////
private void btnSubmit_Click(object sender, System.EventArgs e)
{
Response.Redirect("dg4.aspx?txtboarddate=" +
this.txtboarddate.Text);
}
///////////////////////
page2.aspx script:
//////////////////////////////////////////
<%@ Import Namespace="System.Data"%>

<%@ Import Namespace="System.Data.SqlClient"%>

<script Language="C#" runat="server">

private void Page_Load(object sender, System.EventArgs e)

{

txtstuff = Request.QueryString["txtstuff"];

if(txtstuff != null){

if(txtstuff =="") txtstuff = "Visitor";

}

////txtstuff = Request.QueryString["txtstuff "];

////this.txtstuff .Text = Request.QueryString["txtstuff "];

BindMe();

}

// function to bind the records retrieved

// from the database to "dgrid" grid

void BindMe() {

////

string txtstuff = Request.QueryString["txtstuff"];

// build the connection string

string strConn = "SERVER=xxx.xx.xx.xx;UID=xxx;PWD=xxxx;DATABASE=myd b;";


// connect to the database

SqlConnection objConn = new SqlConnection(strConn);
// query

string strSQL = "SELECT * FROM tblDb where MyDate = '" & txtstuff &
"'";

// create an instance of the DataReader object

SqlCommand objCommand = new SqlCommand(strSQL, objConn);

objConn.Open();

SqlDataReader objReader = objCommand.ExecuteReader();
// assign the DataReader object as the source

// for the "dgrid" grid

dgrid.DataSource = objReader;

dgrid.DataBind();

// free up memory

objReader.Close();

objConn.Close();

}

</script>
???????????????
chumley

Nov 19 '05 #2
No sorry, the querystring name is 'txtstuff', not txtboarddate, as
txtstuff is just a generic example

I thought I was declaring it (???)

Nov 19 '05 #3
You are not declaring the variable. You have 2 things named 'txtstuff'. One
is something you are passing in query string. The other is a variable you
are trying to use on the second page.

Notice that this is a compile time error. Not a runtime error. The compiler
cannot compile your page because you are trying to use a variable you have
not declared. This would be a reason to use code-behind and not put scripts
right in the page - much easier to work out compile time errors in the IDE.

"Chumley Walrus" <sp*******@yahoo.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
No sorry, the querystring name is 'txtstuff', not txtboarddate, as
txtstuff is just a generic example

I thought I was declaring it (???)

Nov 19 '05 #4
I tried declaring as such in the code below, but now I get an error in
my sql statement : Operator '&' cannot be applied to operands of type
'string' and 'string'
////////////////
string rqs = Request.QueryString["txtmystuff"];
string strConn = "SERVER=xx.xx.xx.xx;UID=xx;PWD=xxx;DATABASE=Mydb;" ;
// connect to the database
SqlConnection objConn = new SqlConnection(strConn);

// query
string strSQL = "SELECT * FROM tblDb where OrderDate = '" & rqs & "'";

Nov 19 '05 #5
& is a concatenation operator in VB. Not in C#. You might want to read up
some on C#.

"Chumley Walrus" <sp*******@yahoo.com> wrote in message
news:11*********************@o13g2000cwo.googlegro ups.com...
I tried declaring as such in the code below, but now I get an error in
my sql statement : Operator '&' cannot be applied to operands of type
'string' and 'string'
////////////////
string rqs = Request.QueryString["txtmystuff"];
string strConn = "SERVER=xx.xx.xx.xx;UID=xx;PWD=xxx;DATABASE=Mydb;" ;
// connect to the database
SqlConnection objConn = new SqlConnection(strConn);

// query
string strSQL = "SELECT * FROM tblDb where OrderDate = '" & rqs & "'";

Nov 19 '05 #6
string strSQL = "SELECT * FROM tblDb where OrderDate = '" + rqs + "'";
....is the correct syntax . It all works now

< read up some on C#

But why?, if I can sit on your lap with a big glass of milk and we can
go over it in the book together :o)

Nov 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: London | last post by:
Hello Can you help me. By ASP How can I get the dropdown(control'name)'s selected value? What is it's property'name?
3
by: Chumley Walrus | last post by:
I've got a c# script whereas I am trying to post from a textbox on my firstpage.aspx over to page2.aspx, but the error I get is:The name 'txtstuff' does not exist in the class or namespace...
3
by: Jon | last post by:
Hi, I have hyperlink objects in a datagrid that redirect the user back to the current page with this syntax: <a href="mypage.aspx?id=foo"> When the page reloads, code in Page_Load then takes...
2
by: Hazzard | last post by:
I am trying to figure out how to add an additional value to a querystring collection so that when I click on a datagrid cell, there will be a key to distinguish it from another column's...
2
by: Magnus Blomberg | last post by:
Hello! I'm quite new to ASP.Net and trying to send a variable from one page to another. Om my first page, Index.htm page I have a link as: <a href="Default.aspx?MyID=7">Def 7</a> On...
5
by: Davids | last post by:
when using the page to POST (from a form) I want the page's querystring to be cleared, how do I do that?
3
by: Nick | last post by:
I've created a user control that extracts data from a database. The VB code is all contained in a code-behind file. I'm trying to extract a value from the request.querystring but keep getting...
3
by: Nirmal Singh | last post by:
I am trying to learn ASP.Net 2.0. I have a page which lists Post Numbers in a gridview and returns the selected Post Number. Using this post number I want to display a second page using SQL...
0
by: mohaaron | last post by:
Hello all, I'm having a problem using the ReturnUrl parameter while using FormsAuthentication. If I already have some querystring parameters in the url like this. ...
1
by: mark4asp | last post by:
Ok so my previous message about the vanishing ReturnUrl value was also lost! - grrrr Fate - I'll get my revenge on you - if you think you can toy with me like this! I decided to change the form...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.