Loading ...

PostBack in Classic ASP

 /5
0 (0votes)

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 !

Comments (no comments yet)

Top Posts