This topic is locked
[SOLVED]

 Session Variables empty

5/17/2011 4:10:59 PM
ASPRunnerPro General questions
B
beachldy author

I've reviewed a bunch of posts on here and the help files, looking at how to work with session variables, but not finding an answer to the problem below. This is on a VIEW page that I'm working on. I've been advised that "you do not have access to field values in 'ASP code snippet'." and am not sure why I cannot get the form's values from code behind a button.
So, I'm trying to use a SQL strings to get the values. Evidently, the 'request.querystring("SchID") isn't getting the value. And I'm sure the problem is that I'm not not using the right method to get the SCHID that is on the form. Once I get an initial starting point (SchID), then I can get other field values to send in an email.

--------------------

if request.querystring("SchID") <> "" then

SchID = request.querystring("SchID")

Session("SchID") = SchID

end if

SchID = Session("SchID")
str = "Select from dbo.tblSchedules where SchID = '" & SchID & "'"

Set rstmp = server.CreateObject("ADODB.Recordset")

rstmp.open str,dbConnection

if not rstmp.eof then

'Session("SchID") = rstmp("SchID")

Session("DriverID") = rstmp("DriverID")

Session("DriverID") = rstmp("DriverID")

Session("CustID") = rstmp("CustID")

end if

rstmp.close

set rstmp=nothing

DriverID = Session("DriverID")
str = "Select
from dbo.tblDrivers where DriverID = '" & DriverID & "' " -- EMPTY DriverID

str = "Select * from dbo.tblDrivers where DriverID = '" & Session("DriverID") & "' " -- GIVES ERROR (syntax?)

------------------------------------------------------

All the above Session("fields") are returned empty.

B
beachldy author 5/17/2011

Forgot to mention that I'm not putting that code on the button's ASP snippet now, but on the View Page "before process" event. Tried it both places unsuccessfully.

Sergey Kornilov admin 5/17/2011

Your code expects Request.QueryString("SchID") to be populated and obviously it is not.
I guess you need to check the following article that explains what QueryString is, how it works and how it can help you:

http://www.w3schools.com/ASP/coll_querystring.asp

B
beachldy author 5/18/2011

I found that the SchID should be "editid1" but still gets no results.
If request.querystring("editid1") <> "" then

SchID = request.querystring("editid1")

Session("SchID") = SchID

end if

SchID = Session("SchID")

B
beachldy author 5/18/2011

Sergey, sorry but I don't understand what you mean by "Your code expects Request.QueryString("editid1") to be populated".
Aren't I querying the url to get the value of the 6 at the end? The 6 is the SchID value. For example, the URL reads
http:...........tblSCHEDULES_view.asp?editid1=6. I want to grab the 6 and make it a var.

B
beachldy author 5/18/2011

On code behind pages, I can get variables by doing this:
SchID = values("SchID")
But if trying to get the values from a code snippet or behind a button, that does not work, as does nothing else I've posted above. I've spent days trying to figure out why I cannot get the value. I know it's something simple, but nothing I've researched gets the value. I've gone to countless sites and forums to find out what is wrong, and found what I've coded is normal. Yet, it does not work. There are so many ways to get the value. I've tried every method I can think of to get the value....So I guess I'm lost here now. Stumped and probably just fried out of trying too hard after 16 hours on the same thing.

B
beachldy author 5/19/2011

Have had two web programmers come over and take a look, and they too, are stumped as I am, and both have been doing web apps since 2000. So, I guess all three of us are idiots, lol. Why can't I get the values of a form into a code snippet? Would using javascript do this? var myfield = document.getElementById('field')?

Sergey Kornilov admin 5/19/2011

You follow the wrong route.
Somebody still needs to read 'Insert PHP/ASP code snippet->Session variables' section at http://xlinesoft.com/blog/2011/04/28/taming-the-beast-events-buttons-and-code-snippets.
This section explains how to make any field value accessible via Session variables on Edit/View pages.