Showing posts with label ASP classic. Show all posts
Showing posts with label ASP classic. Show all posts

13 September, 2007

Altering QueryString with Javascript

I'm making a grid in a legacy ASP application. That's right kids, ASP as in Active Server Pages. Old School stuff. None of the ultra-kewl .NET does it all for you stuff. Which, BTW, I really love because I can do so much more so much faster and better. But, alas, the client says "ASP only!" so, I go with ASP.

What they wanted to do was display their data in a grid. Yeah, right, ASP and datagrids, that is a rich one. So what I did was something almost, but not quite, completely different from a grid. I put their data in an HTML table with alternating row colors (hey, at least they think it's in a grid).

But of course, in any good datagrid, one must be able to click on the grid headers and VOILA! the grid sorts by the header clicked. This, I figured out, to do with JavaScript via the QueryString. The table is in an IFRAME, so the URL is never displayed to the end user. Doing this keeps the displayed URL fairly nice and neat. My original though, which seemed to work fairly well was just to cut the QueryString off at the desired parameter, and replace that parameter with the new one as such:

function reSortGrid(str)
{
var idx = location.href.indexOf('&sortby');
var loc = location.href.substring(0, idx);
loc = loc + '&sortby=' + str;
location.href = loc;
}
But then it occurred to me that if any parameters existed beyond the parameter I was replacing, they would be lost. No, what I really needed was to replace the existing sortby parameter within the actual string, while maintaining the rest of the string. This took a little thinking on my part, and what I came up with is:
function resortGrid(str)
{
var newQueryString = '';
if (location.href.indexOf('&sortby') > -1)
{
var locArray = new Array();
locArray = location.href.split('&');
for (i=0; iif (locArray[i].indexOf('sortby') > -1)
{
locArray[i] = "sortby=" + str;
// check to see if this is the start of the QueryString
if (locArray[i].indexOf('?') == -1)
newQueryString = newQueryString + '&' + locArray[i];
else
newQueryString = locArray[i];
}
}else{
newQueryString = location.href + '&sortby=' + str;
}
location.href = newQueryString;
}
So what I ended up with is a QueryString with the correct parameter changed, and the rest of the parameters intact.

14 August, 2007

Old School

This is becoming less of a blog about C# lately, and more of a blog about web programming in general. Hopefully I'll get back to C# sooner, rather than later.

Currently, my project is to enhance and expand an application written in ASP and...get this...Delphi!!!! And I have to tell you, after using C# and ASP.NET for the past 5 years, ASP SUCKS!! And not just a little, ASP sucks splendidly!

The current problem I fighting with is accessing an MS Access database via ASP. Getting there the first time isn't too bad, but when I try to get to it a second time, it blows up with that oh so informative error of:
Provider error '80004005'

Unspecified error

/Bridge/facilities/facmain.inc, line 13

Now, if Microsoft could any more ambiguous, I don't know how. It looks like I'm going to have make a separate DB connection for each RecordSet. This seems stupid and entirely inefficient, but as Duke Wayne said "A man's gotta do what a man's gotta do."

I am seriously not wanting to delve into that Delphi portion of the project, but that is coming soon enough.




Technorati Tags: , ,