469,336 Members | 5,527 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,336 developers. It's quick & easy.

posting to server but staying on same page

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
Jul 19 '05 #1
15 3936
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()%>">

--

Ray at home
Microsoft ASP MVP
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
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

Jul 19 '05 #2
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
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?


Honestly, you will be better off refreshing the page, if for no better
reason than to remain consistent with the rest of the web. If the user
clicks a button to submit, and they don't see their browser doing anything,
I think most people would come to the assumtion that something was wrong and
start clicking submit over and over or going Back and Forward trying to
figure out why there browser stopped working.

Why not do something like this:
User submits the form to a page that does the processing, but does not
display anything. At the end of the processing, Response.Redirect back to
the previous page, so the user ends up on the same page but they would have
seen some action to let them know something happened.

Regards,
Peter Foti


Jul 19 '05 #3
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
"Peter Foti" <pe***@Idontwantnostinkingemailfromyou.com> wrote in message
news:10*************@corp.supernews.com...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uH**************@TK2MSFTNGP12.phx.gbl...
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?


Honestly, you will be better off refreshing the page, if for no better
reason than to remain consistent with the rest of the web. If the user
clicks a button to submit, and they don't see their browser doing

anything, I think most people would come to the assumtion that something was wrong and start clicking submit over and over or going Back and Forward trying to
figure out why there browser stopped working.

Why not do something like this:
User submits the form to a page that does the processing, but does not
display anything. At the end of the processing, Response.Redirect back to
the previous page, so the user ends up on the same page but they would have seen some action to let them know something happened.

Regards,
Peter Foti

Jul 19 '05 #4
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
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.
How are those values passed to the form? You will likely need to duplicate
this method when you redirect back to this 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.


I'm not sure what you mean here. It sounds like you have:

1 page containing a form, form is submitted to page 2, which uses the
submitted values from the first form to create a new form. Form 2 submits
to page 3, which redirects back to page 2, but none of the form items are
being passed correctly back to page 2 from page 3.

Does that describe the problem?

I suspect you are doing something like this:
Page 1 submits the form using method POST. Page 2 gets the values from the
Request.Form collection. Thus, when page 3 redirects back, there is no
Request.Form collection. Unfortunately, there's no good way to to pass the
Request.Form collection back without using client side script to submit a
form. You might be able to use method GET, and pass the form back in the
query string, but I generally try to avoid using GET to pass form data.

An alternative might be to redirect back to page 1.

-Peter

Jul 19 '05 #5
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
"Peter Foti" <pe***@Idontwantnostinkingemailfromyou.com> wrote in message
news:10*************@corp.supernews.com...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uw**************@tk2msftngp13.phx.gbl...
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.


How are those values passed to the form? You will likely need to

duplicate this method when you redirect back to this 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.


I'm not sure what you mean here. It sounds like you have:

1 page containing a form, form is submitted to page 2, which uses the
submitted values from the first form to create a new form. Form 2 submits
to page 3, which redirects back to page 2, but none of the form items are
being passed correctly back to page 2 from page 3.

Does that describe the problem?

I suspect you are doing something like this:
Page 1 submits the form using method POST. Page 2 gets the values from

the Request.Form collection. Thus, when page 3 redirects back, there is no
Request.Form collection. Unfortunately, there's no good way to to pass the Request.Form collection back without using client side script to submit a
form. You might be able to use method GET, and pass the form back in the
query string, but I generally try to avoid using GET to pass form data.

An alternative might be to redirect back to page 1.

-Peter

Jul 19 '05 #6
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
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?


This article discusses how:

http://www.aspfaq.com/show.asp?id=2321

Regards,
Peter Foti
Jul 19 '05 #7
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.

"Peter Foti" <pe***@Idontwantnostinkingemailfromyou.com> wrote in message
news:10************@corp.supernews.com...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
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?
This article discusses how:

http://www.aspfaq.com/show.asp?id=2321

Regards,
Peter Foti

Jul 19 '05 #8
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

"Peter Foti" <pe***@Idontwantnostinkingemailfromyou.com> wrote in message
news:10************@corp.supernews.com...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
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?
This article discusses how:

http://www.aspfaq.com/show.asp?id=2321

Regards,
Peter Foti

Jul 19 '05 #9
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.


? Did you forget to post your code? :)

-Peter
Jul 19 '05 #10
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
"Peter Foti" <pe***@Idontwantnostinkingemailfromyou.com> wrote in message
news:10*************@corp.supernews.com...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
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.


? Did you forget to post your code? :)

-Peter

Jul 19 '05 #11
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uo****************@TK2MSFTNGP11.phx.gbl...
yes I did. sorry about that.
Here is the code that I want to run again after I return from the server. <snip> 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========


I am suspicious of this:
left(request.form("selectmeasure"),instr(request.f orm("selectmeasure"),":")-
1)

Try this:

Response.Write "<div>" & request.form("selectmeasure") & "</div>"
Response.Write "<div>" & instr(request.form("selectmeasure"),":") & "</div>"
Response.Write "<div>" & instr(request.form("selectmeasure"),":")-1 &
"</div>"

You should be doing some sort of validation. If, for example, ":" is not
found, instr will return 0 and you'll have -1 as the length parameter of the
Left() function, which is bad.

Really, the only thing I can suggest is add more validation and try printing
out all of the values as you go so you can find where the problem is.

Peter


Jul 19 '05 #12
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
"Peter Foti" <pe***@Idontwantnostinkingemailfromyou.com> wrote in message
news:10*************@corp.supernews.com...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
news:uo****************@TK2MSFTNGP11.phx.gbl...
yes I did. sorry about that.
Here is the code that I want to run again after I return from the server.
<snip>
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========
I am suspicious of this:

left(request.form("selectmeasure"),instr(request.f orm("selectmeasure"),":")- 1)

Try this:

Response.Write "<div>" & request.form("selectmeasure") & "</div>"
Response.Write "<div>" & instr(request.form("selectmeasure"),":") & "</div>" Response.Write "<div>" & instr(request.form("selectmeasure"),":")-1 &
"</div>"

You should be doing some sort of validation. If, for example, ":" is not
found, instr will return 0 and you'll have -1 as the length parameter of the Left() function, which is bad.

Really, the only thing I can suggest is add more validation and try printing out all of the values as you go so you can find where the problem is.

Peter



Jul 19 '05 #13
"wk6pack" <wk***@sd61.bc.ca> wrote in message
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
Jul 19 '05 #14
Nice to see you here Jenny! :]

Ray at work

"jenny mabe" <ne**@rabidduck.com> wrote in message
news:opr3yjlnqhqafk40@localhost...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
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
Jul 19 '05 #15
Thanks Jenny. I will try that next time. I never thought about using
iframes before.

Will
"jenny mabe" <ne**@rabidduck.com> wrote in message
news:opr3yjlnqhqafk40@localhost...
"wk6pack" <wk***@sd61.bc.ca> wrote in message
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
Jul 19 '05 #16

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Jonathan M. Rose | last post: by
3 posts views Thread by A.S. | last post: by
1 post views Thread by Allan Cammish | last post: by
10 posts views Thread by DaveFash | last post: by
13 posts views Thread by Ian.Suttle | last post: by
2 posts views Thread by Rabbit | last post: by
1 post views Thread by ArunDhaJ | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.