Showing posts with label headache. Show all posts
Showing posts with label headache. Show all posts

Friday, March 16, 2012

Passing A Variable ~ Headache needs Cure!!

Hi All,

I have been trying to pass a variable all day and I am very nealry there...I have been through three books and obviously this prob is too easy for books

passing a variable form page 1 to 2

page one code

This a snippet but it all works and I have tested I get my variable by doing a response.write

<code/
strName = dslogin.tables("UserInfo").rows(0).item("ID")
Session.Item("UserID")=strNAme
response.redirect("./success10.aspx")

</code
Page 2 Code

<code/>
sub page_load(byval sender as object, byval e as eventargs)

dim strNAme as string = Session.Item("UserID")

response.write("hello " & strNAme)

end sub

</code
I get the referring page (/success10.aspx) but the variable does not get written in the response.write test

Any help would be greatly apprecitated.......I can then go to bed....:)

rgs

TonyJust a suggestion, but why don't you try using a Cookie or a QueryString instead?
Hi

Thanks for the post.......

I dont want to use a cookie as not everyone has them turned on......and I have never used session variables so its good learning....

cheers

Tony
Try this...


First Page.

Session("UserID")=strNAme

Second Page.

dim strNAme as string = Session("UserID")


Session("blah") = "Hello There!"
Response.Write(Session("blah"))

Try debugging the string variable and make sure that it contains a value.

Edit: And as another poster said, maybe you should be looking into querystrings since you're trying to "pass" variables to another page.
Basically, you are losing your session as soon as you redirect. Redirect() actaully executes a Response.End as soon as the header is sent, thus losing your session (which is stored in a cookie on the client). Try using the following overload method of Redirect():

Response.Redirect("~/SomePage.aspx", false);

The second parameter tells the method whether or not to execute a call to Response.End(). By default, if not specified, it is set to TRUE, and wa la.. you lose your session. If set to FALSE, a call to Response.End isn't called and you should be OK. :-)

Another alternative is to use Server.Transfer(). However, the URL will stay the same in the client's browser, as opposed to Response.Redirect().

Here is a decent explanation:
http://blogs.msdn.com/bleroy/archive/2004/08/03/207486.aspx

Hopefully this will point you in the right direction.

Let me know how it turns out.

Passing a Variable?

Hi All,

Having an issue when passin a variable form one page to another.....can anyone please make this headache go away by point out the eror of my ways..Have a feeling its sql statement.......(as always!!!!)

Any help would be most appreciated,,

Cheers

Tony

CODE

Dim lota as string
Public strSearch as string
Public strSearcha as string
Dim counta as string

Sub Page_Load(ByVal Sender as Object, ByVal E as EventArgs)

lota = Request.QueryString("lota")

If Not Page.IsPostBack Then
'if Not IsPostBack Then
Dim DBConn as OleDbConnection
Dim DBCommand As OleDbDataAdapter
Dim DSPageData as New DataSet
DBConn = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" _
& "DATA SOURCE=" _
& Server.MapPath("/fpdb/" _
& "auction.mdb;"))
DBCommand = New OleDbDataAdapter _
("Select Distinct LotDescription " _
& "From Table1 " _
& "Where Date = & lota & "
& "Order By LotDescription", DBConn)
DBCommand.Fill(DSPageData, _
"LotDescription")
ddlZipCode.DataSource = _
DSPageData.Tables("LotDescription").DefaultView
ddlZipCode.DataBind()
dbconn.close
end if
end sub

Error Message

Server Error in '/' Application.
------------------------

Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: BC30311: Value of type 'String' cannot be converted to 'System.Data.OleDb.OleDbCommand'.

Source Error:

Line 30: & "auction.mdb;"))
Line 31: DBCommand = New OleDbDataAdapter _
Line 32: ("Select Distinct LotDescription " _
Line 33: & "From Table1 " _
Line 34: & "Where Date = & lota & "you need to create an additional object of type OleDbCommand.


Dim DBcommand As New OleDb.OleDbCommand
DBcommand.CommandText = "select * from table1"
DBAdapter = new OleDbDataAdapter(DBcommand)