posting to server but staying on same page

W

wk6pack

Hi,

I have a problem and not quite how to go about solving it.

I have a form written in asp. I wish to submit the form and have the server
return back to the same page without actually refreshing the page.

I know I could write a form, submit it and go to another page.

I've searched the web and I see something about HTTP Status code of 204
would return no content to the client browser. How would I incorporate this
into my asp page? How do I detect a HTTP status codes in asp?

Is there a better way to do this?

thanks,
Will
 
R

Ray at

Well, if you submit the form, the page will have to refresh. You can try
something like:


<%
Function Self()
Dim sPath, aParts
sPath = Request.ServerVariables("SCRIPT_NAME")
aParts = Split("/" & sPath, "/")
Self = Trim(LCase(aParts(UBound(aParts))))
End Function
%>

<%
If Request.ServerVariables("REQUEST_METHOD") = "POST" Then
'''other ways to check for post, like If Request.Form("hiddeninput") <>
"" Then ...
'''your code here
End If
%>

<form method="post" action="<%=Self()%>">
 
W

wk6pack

Hi Peter,

That was my original intention. The users prefer to have that do nothing.
Since you need to submit the form, I'm trying to submit the form and then
have the next form either redirect back or using meta tags to automatically
bring that original page back.

The form that I am submitting, needs values from the previous page. These
values then create a sql statement and populate the page. When I submit the
form to another asp to do the processing on the server, I then come back to
the form that was submitted but it doesnt seem to remember any of the values
on that page even though I have them hidden on the asp page that is
returned.

Any ideas?

thanks,
Will
 
W

wk6pack

What you said is correct. That is what I'm doing.

If I use Response.redirect("score.asp") I still dont get the form variables.
If I use meta tag <meta http-equiv=""refresh"" content=""1;url=score.asp""
/>
I dont get them either. Is there a way to get them after I process the
submitted form?
You said something to do with client side scripting, how would I use this?

I agree about using GET method.

thanks,
Will
 
W

wk6pack

Thanks, for the faq. What seems to be happening now is I get the
parameters in the form but it doesnt seem to recognize the strsql that is in
the form.

here is the code from the page that i'm trying to run after I post to the
server.
 
W

wk6pack

Thanks for the faq. It doesnt seem to be running the asp code on the page
that was posted.

Here is the code that I want to run again after I return from the server.

set cn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
set pmrs = Server.CreateObject("ADODB.Recordset")
dim strSQL
cn.Open "Provider=SQLOLEDB;Data Source=Regulus;Initial Catalog=" & ldb &
";User ID=" & luser & ";Password=" & lpwd

' string looks like 1:1:smith, john:01:13
lclass = request.form("selectclass")
strlen = len(lclass)
dim classarray(10)
cnt = 0
colonpos = instr(lclass,":")
tmpstr = lclass
lschoolkey = Left(tmpstr,colonpos - 1)
classarray(0) = lschoolkey
i=1
if session("spschooltype") <> "S" then
'elementary schools have a division
params = 4
else
params = 3
end if
while i < params
tmpstr = mid(tmpstr,colonpos + 1, strlen)
colonpos = instr(tmpstr,":")
classarray(i)= left(tmpstr,colonpos - 1)
i = i + 1
wend
'get the last element into the array
if params = 3 then
tmpstr = mid(tmpstr,colonpos+1, strlen)
classarray(params) = left(tmpstr,instr(tmpstr,":")-1)
else
classarray(params) = right(tmpstr,2)
end if
strSQL = " select b.school_key, b.Teacher, b.Grade, b.Division, " & _
" c.Student_key, c.Student_ID, c.Student_Name,
d.Performance_Measure_key, d.Score, e.performance_measure, b.class_key " & _
" from dbo.Class b, dbo.Student c, dbo.Score d, performance_measure e "
& _
" where d.class_key = b.class_key " & _
" and c.student_key = d.student_key " & _
" and d.performance_measure_key = e.performance_measure_key and
d.performance_measure_key = " & left(request.form("selectmeasure"),
instr(request.form("selectmeasure"),":")-1) & " " & _
" and b.school_key = " & classarray(0) & " and b.class_key = " &
classarray(1) & " " & _
" and b.Teacher = '" & classarray(2) & "' and b.grade = '" &
classarray(3) & "' "
response.write "sql string first=" & strsql <=============THIS IS BLANK ON
THE SCREEN========
if params = 4 then
strSQL = strSQL & " and b.division='" & classarray(4) & "' " & " order by
b.teacher, b.grade, b.division, c.student_name "
else
strSQL = strSQL & " order by b.teacher, b.grade, c.student_name "
end if
' response.write "sql string second=" & strsql
rs.open strsql, cn , 1, 1
if err.number <> 0 then <===============THEN IT GIVES ME AN ERROR HERE
BECAUSE THE STRSQL IS BLANK>

thanks again for you help, Peter,
Will
 
W

wk6pack

yes I did. sorry about that.
Here is the code that I want to run again after I return from the server.

set cn = Server.CreateObject("ADODB.Connection")
set rs = Server.CreateObject("ADODB.Recordset")
set pmrs = Server.CreateObject("ADODB.Recordset")
dim strSQL
cn.Open "Provider=SQLOLEDB;Data Source=Regulus;Initial Catalog=" & ldb &
";User ID=" & luser & ";Password=" & lpwd

' string looks like 1:1:smith, john:01:13
lclass = request.form("selectclass")
strlen = len(lclass)
dim classarray(10)
cnt = 0
colonpos = instr(lclass,":")
tmpstr = lclass
lschoolkey = Left(tmpstr,colonpos - 1)
classarray(0) = lschoolkey
i=1
if session("spschooltype") <> "S" then
'elementary schools have a division
params = 4
else
params = 3
end if
while i < params
tmpstr = mid(tmpstr,colonpos + 1, strlen)
colonpos = instr(tmpstr,":")
classarray(i)= left(tmpstr,colonpos - 1)
i = i + 1
wend
'get the last element into the array
if params = 3 then
tmpstr = mid(tmpstr,colonpos+1, strlen)
classarray(params) = left(tmpstr,instr(tmpstr,":")-1)
else
classarray(params) = right(tmpstr,2)
end if
strSQL = " select b.school_key, b.Teacher, b.Grade, b.Division, " & _
" c.Student_key, c.Student_ID, c.Student_Name,
d.Performance_Measure_key, d.Score, e.performance_measure, b.class_key " & _
" from dbo.Class b, dbo.Student c, dbo.Score d, performance_measure e "
& _
" where d.class_key = b.class_key " & _
" and c.student_key = d.student_key " & _
" and d.performance_measure_key = e.performance_measure_key and
d.performance_measure_key = " & left(request.form("selectmeasure"),
instr(request.form("selectmeasure"),":")-1) & " " & _
" and b.school_key = " & classarray(0) & " and b.class_key = " &
classarray(1) & " " & _
" and b.Teacher = '" & classarray(2) & "' and b.grade = '" &
classarray(3) & "' "
response.write "sql string first=" & strsql <=============THIS IS BLANK ON
THE SCREEN========
if params = 4 then
strSQL = strSQL & " and b.division='" & classarray(4) & "' " & " order by
b.teacher, b.grade, b.division, c.student_name "
else
strSQL = strSQL & " order by b.teacher, b.grade, c.student_name "
end if
' response.write "sql string second=" & strsql
rs.open strsql, cn , 1, 1
if err.number <> 0 then <===============THEN IT GIVES ME AN ERROR HERE
BECAUSE THE STRSQL IS BLANK>

thanks again for you help, Peter,
Will
 
W

wk6pack

Hi Peter,

Thanks for all you help. I figured it out. It was the script to submit the
form and the fact that the hidden values were not in between the form tags.

You're right, I should do some more checks on the value before calling any
functions.

Will
 
J

jenny mabe

wk6pack said:
I have a form written in asp. I wish to submit the form and have the
server return back to the same page without actually refreshing the page.

another way to create this behaviour is to place an iframe on your form
page, and use javascript to send the values from this form, when the
submit button is pressed (or you can use a link or other clickable
element), to your processing page in the iframe. use asp to process the
form, and then write out javascript to replace the values in the form
fields with the values returned by your form -- only if they change, as
the values entered by the user will stay as they were entered and the page
will not be refreshed. this is a good way to use asp to generate something
on the screen but you dont want to have to go to another screen or you
want to be able to use javascript to return alerts or do dhtml actions.


jenny
 
R

Ray at

Nice to see you here Jenny! :]

Ray at work

wk6pack said:
I have a form written in asp. I wish to submit the form and have the
server return back to the same page without actually refreshing the page.

another way to create this behaviour is to place an iframe on your form
page, and use javascript to send the values from this form, when the
submit button is pressed (or you can use a link or other clickable
element), to your processing page in the iframe. use asp to process the
form, and then write out javascript to replace the values in the form
fields with the values returned by your form -- only if they change, as
the values entered by the user will stay as they were entered and the page
will not be refreshed. this is a good way to use asp to generate something
on the screen but you dont want to have to go to another screen or you
want to be able to use javascript to return alerts or do dhtml actions.


jenny
 
W

wk6pack

Thanks Jenny. I will try that next time. I never thought about using
iframes before.

Will
wk6pack said:
I have a form written in asp. I wish to submit the form and have the
server return back to the same page without actually refreshing the page.

another way to create this behaviour is to place an iframe on your form
page, and use javascript to send the values from this form, when the
submit button is pressed (or you can use a link or other clickable
element), to your processing page in the iframe. use asp to process the
form, and then write out javascript to replace the values in the form
fields with the values returned by your form -- only if they change, as
the values entered by the user will stay as they were entered and the page
will not be refreshed. this is a good way to use asp to generate something
on the screen but you dont want to have to go to another screen or you
want to be able to use javascript to return alerts or do dhtml actions.


jenny
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top