posting to server but staying on same page

Discussion in 'ASP General' started by wk6pack, Feb 19, 2004.

  1. wk6pack

    wk6pack Guest

    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
     
    wk6pack, Feb 19, 2004
    #1
    1. Advertising

  2. wk6pack

    Ray at Guest

    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" <> wrote in message
    news:...
    > 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
    >
    >
     
    Ray at, Feb 19, 2004
    #2
    1. Advertising

  3. wk6pack

    wk6pack Guest

    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" <> wrote in message
    news:...
    > "wk6pack" <> wrote in message
    > news:...
    > > 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
    >
    >
    >
    >
     
    wk6pack, Feb 20, 2004
    #3
  4. wk6pack

    wk6pack Guest

    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" <> wrote in message
    news:...
    > "wk6pack" <> wrote in message
    > news:uw$...
    > > 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
    >
    >
    >
     
    wk6pack, Feb 20, 2004
    #4
  5. wk6pack

    wk6pack Guest

    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" <> wrote in message
    news:...
    > "wk6pack" <> wrote in message
    > news:%237rqW7%...
    > > 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
    >
    >
     
    wk6pack, Feb 20, 2004
    #5
  6. wk6pack

    wk6pack Guest

    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" <> wrote in message
    news:...
    > "wk6pack" <> wrote in message
    > news:%237rqW7%...
    > > 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
    >
    >
     
    wk6pack, Feb 20, 2004
    #6
  7. wk6pack

    wk6pack Guest

    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" <> wrote in message
    news:...
    > "wk6pack" <> wrote in message
    > news:%2319m$s$...
    > > 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
    >
    >
     
    wk6pack, Feb 20, 2004
    #7
  8. wk6pack

    wk6pack Guest

    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" <> wrote in message
    news:...
    > "wk6pack" <> wrote in message
    > news:uo%23GC6$...
    > > 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.form("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
    >
    >
    >
    >
    >
    >
    >
    >
     
    wk6pack, Feb 23, 2004
    #8
  9. wk6pack

    jenny mabe Guest

    "wk6pack" <> 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
     
    jenny mabe, Feb 26, 2004
    #9
  10. wk6pack

    Ray at Guest

    Nice to see you here Jenny! :]

    Ray at work

    "jenny mabe" <> wrote in message
    news:eek:pr3yjlnqhqafk40@localhost...
    "wk6pack" <> 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
     
    Ray at, Feb 26, 2004
    #10
  11. wk6pack

    wk6pack Guest

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

    Will
    "jenny mabe" <> wrote in message
    news:eek:pr3yjlnqhqafk40@localhost...
    "wk6pack" <> 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
     
    wk6pack, Feb 26, 2004
    #11
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Michael Scovetta
    Replies:
    0
    Views:
    3,102
    Michael Scovetta
    Jun 4, 2003
  2. tshad
    Replies:
    7
    Views:
    441
    tshad
    Jan 4, 2005
  3. Patio87
    Replies:
    4
    Views:
    418
    Julie
    Aug 18, 2004
  4. Irmen de Jong
    Replies:
    0
    Views:
    689
    Irmen de Jong
    Jun 25, 2003
  5. Peter Hansen
    Replies:
    1
    Views:
    702
    Amos Joshua
    Jun 29, 2003
Loading...

Share This Page