AJAX and COM+ (client-side and server-side simultaneously)
@Markdidj ;
"You do realise I'm using asyncronous javascript to fire server-side code?"
"The only thing I like about .NET is the OOP, making it easier for me to make my programming simple to follow by others, but OOP isn't neccessary for a good website."
You got a VERY good point here.
@logic_earth
".NET however, C# in this case is an object-oriented language at its core. It requires a different train of thought with switching between the two paradigms."
"They are called callback (or events) Javascript supports these as well...I'm surprised you haven't used those yet in Javascript..."
Yes, javascript (eventually AJAX) will switch the client-side to server-side (ASP) eventuality. And it is the main train.
Let me point out some codes here (javascript/AJAX calling a server-side classic ASP, tied with a COM+ dll)
accountNameSearch.JS
Code:
var a;
/* Searching Customer Name Records */
function srchCustName(varName){
if(varName.length>0){
var b="accountNameSearch.asp?sid="+Math.random()+"&qAction=iNFO&qCustname="+varName;
a=GetXmlHttpObject(nameResult);
document.getElementById("nameDiv").style.display='';
document.getElementById("nameDiv").innerHTML="<img src='/images/arrow.gif'/>";
a.open("GET",b,true);a.send(null);}
else{
document.getElementById("nameDiv").style.display='none';
document.getElementById("nameDiv").innerHTML="";}}
function nameResult(){
if(a.readyState==4||a.readyState=="complete"){
document.getElementById("nameDiv").innerHTML=a.responseText;}}
/* Asynchronous Javascript browser picker */
function GetXmlHttpObject(handler){
var d=null;
if(navigator.userAgent.indexOf("MSIE")>=0){
var e="Msxml2.XMLHTTP";
if(navigator.appVersion.indexOf("MSIE 5.5")>=0){
e="Microsoft.XMLHTTP";}
try{
d=new ActiveXObject(e);
d.onreadystatechange=handler;
return d;}
catch(e){
alert("Browser Error. Unable to perform AJAX feature");
return;}}
if(navigator.userAgent.indexOf("Mozilla")>=0 || navigator.userAgent.indexOf("Opera")>=0){
d=new XMLHttpRequest();
d.onload=handler;
d.onerror=handler;
return d;}}
accountNameSearch.ASP
Code:
<%
'Function: to Trim the spaces in the string and convert to Uppercase
Function UpCase(StringtoBeUppercase)
UpCase = UCase(Trim(StringtoBeUppercase))
End Function
Dim action, itemResults, sessID, acctNo, acctName
action = trim(request.QueryString("qAction"))
if action = "iNFO" then
sessID = session("sessionUsrID")
acctNo = ""
acctName = UpCase(request.QueryString("qCustname"))
tmpAcctName = acctName
itemResults = "<div style='background:#fff; border:1px #ccc solid; margin-left:1px; width:400px;'><table width='100%' cellpadding='2px' cellspacing='2px'>"
if tmpacctName <> "" then
'
'COMponent in DLL form (installed using COM+)
stat = banksObj.searchAccountName(tmpAcctName, acctNo, sessID)
end if
if stat ="00" then
for ctr = 1 to 15
'
'COMponent in DLL form (installed using COM+)
stat = banksObj.searchAccountName(acctName, acctNo, sessID)
if stat <> "00" then
exit for
else
if ctr mod 2 then
itemResults = itemResults + "<tr bgcolor='#eeeeee'>"
else
itemResults = itemResults + "<tr bgcolor='white'>"
end if
itemResults = itemResults + "<td style='width:270px'><a href='nameSearch.asp?qFunc=jxSelected&qAfid894nxo=" & trim(acctNo) & "&qNm98ns7hsi3=" & trim(server.URLEncode(acctName)) & "' style='font-size:12px; color:#6633ff; font-weight:bold;'>" & trim(server.HTMLEncode(acctName)) & "</a></td><td align='left' style='width:130px;'> " & trim(acctNo) & "</td></tr>"
end if
next
else
if tmpacctName <> "" then
itemResults = "<tr><td><h5 style='color:red; padding-left:5px;'>No customer accounts found....</h5></td><tr>"
end if
end if
itemResults = itemResults + "</table></div>"
response.write(itemResults)
end if
%>
The code is a very powerful classic ASP that is tied to a COM+ wrapper (created DLLfile - Cobol in my case, it is not even C#). You can create a <form>... </form> that could use the accountNameSearch.JS to invoke the second ASP (in this case accountNameSearch.ASP to get the account name being type in a form using onKeyUp="srchCustName(this.value)" javascript event. With this simple code, a pop-up box may even be used to display the names in your back-end server-side database.
At this point, I think "Markdidj" has a very good point that you do not need an OOP to create a Google thing autosearch box.