Vivek Thakur

Chaotically Complex

  Home  |   Contact  |   Syndication    |   Login
  105 Posts | 1 Stories | 498 Comments | 65 Trackbacks

News



Archives

ASP.NET Ventures

*******************
Note: view the updated entry below:

http://www.codeasp.net/blogs/vivek_iit/microsoft.net/17/postback-in-classic-asp

*******************


Many of the "new" developers might not value the ASP.NET framework when compared to classic ASP (ASP 3.0). Life was really tough and "messy" in the old days when just to post data on a form intermediate forms were used. Even a simple thing like IsPostBack property in ASP.NET was not available in ASP.

Recently I was working on a community project which had a particular section coded in ASP 3.0 while all other sections were in ASP.NET. So for tasks like maintaining session across ASP and ASP.NET pages I had to sometime use cookies and other times this nice technique by Peter Bromberg.

At one time I got stuck in a minor issue where I needed to know if the Select option html control (the advanced version of which is the DropDownList control in ASP.NET) had caused the page to post or if it was a simple GET request. The Select option HTML control does not post to the page when you change the selected option (unlike the DropDownListControl with AutoPostBack set to true). So I had had used JavaScript code to submit the form on the "onchange" event as:

 <select name="aspDropDown" id="htmlSelectPart" onchange="javascript:doPostBack();">

function doPostBack()
{
   document.forms[0].submit();
}

This is more or less the same thing what ASP.NET does while posting the form when the DropDownList control's selected item is changed.

Now to know if the form has been posted due to the select option item change I used Request.ServerVariables property in ASP which will return me the type of request made to the current page (GET/POST etc):

//classic asp code

var checkPostBack = new String(Request.ServerVariables("REQUEST_METHOD"))

if (checkPostBack == "POST")
{
   //form has been posted, which might be due to the select option controls item change event
}

else
{
   //a get request..code accordingly
}

This worked as expected and made me wonder how tough the life of ASP developers must have been! ASP.NET has really made web programming so much easier and comfortable that sometimes most of the beginner web developers think that ASP.NET development is as easy as similar to windows forms development and almost forget that they are coding in a stateless HTTP environment !

posted on Saturday, April 14, 2007 1:36 PM

Feedback

# re: PostBack in Classic ASP 4/26/2007 5:25 AM Anton
Hi Vivek,
Guess you have not worked much with ASP.

You could have just used Request object and then the ID of the control.
This would have got you the value irrespective of wether its a POST or a GET.

you also have Request.Form and Request.QueryString for specific tasks.

Unlike ASP.NET ASP does allow mutiple forms and submitting a form by GET instead of the default POST.

Happy programming,
Anton


# re: PostBack in Classic ASP 4/26/2007 6:06 AM Vivek
Anton,

I think you did not understand what I wanted to access. I could have easily accessed control values using Request object, but I wanted to know if the Request is GET or POST (I wanted to differentiate between the two) so that I could emulate the behavior of IsPostBack property in ASP.NET.

Hope this clears things,

Vivek

# re: PostBack in Classic ASP 6/17/2008 8:51 PM Doug Kirschman
The code you listed above...

var checkPostBack = new String(Request.ServerVariables("REQUEST_METHOD"))

if (checkPostBack == "POST")
{
//form has been posted, which might be due to the select option controls item change event
}

else
{
//a get request..code accordingly
}

You call this Classic ASP. This is JavaScript. How would you evaluate the request type (GET vs POST) with VB Script? I want the server to differentiate between GET and POST.

Thanks,

Doug

# re: PostBack in Classic ASP 9/4/2008 4:25 PM Azbola
Doug,

This is still ASP, nothing stops you coding ASP in javascript instead of VBScript. It still runs on the server just different syntax.

The ASP classes are still the same (Request, Response etc)

# re: PostBack in Classic ASP 2/1/2009 1:55 PM Khad7
Thanks alot Vivek

# re: PostBack in Classic ASP 10/8/2009 2:23 AM Sharon
Classic asp version:

<%
checkPostBack = Request.ServerVariables("REQUEST_METHOD")

if (checkPostBack = "POST") then
'Do anything
else
'Do something
end if
%>


Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: