classic asp - call a vbscript function from a button without page reload?

Posted on 2012-09-06
Last Modified: 2012-09-15
Hello: OK, I know I'm not using the lastest and greatest tools but there's a reason for that! I have a legacy classic asp page loading. It uses a querystring parameter, and for my own reasons which are hard to explain to you I don't want to reload the page again.

I'm trying to find a way to update variables on the page by calling a vbscript function 'labelOpen' which reads a database then updates the variables displayed.

What I need to do is call the labelOpen function from a button (or even better onChange of two radio buttons "English" or "French" then update the 'LabelGet[1]' variable and reload the <!-- #INCLUDE file="includes/customlogin/2012studentlogin.asp" -->.

I know I'm paddling upstream. Any way to do this?


<!-- #INCLUDE file="online/simplytracking/includes/clsLayout.asp"-->
<!-- #INCLUDE file="includes/settings2.asp" -->

      Dim strCompanyLoginName, strClientID, strVersion, strLanguageCode, SqlQuery, obj, rs, ptr


      Dim rsLabels

      Public Sub labelOpen ( LabelPage, LabelLang )
            Set      rsLabels = Server.CreateObject("ADODB.Recordset")
            rsLabels.ActiveConnection      = objConnection
            rsLabels.CursorLocation = 3
            rsLabels.Open "SELECT * FROM Labels WHERE FileName='" & LabelPage & "' AND LanguageCode='" & LabelLang & "'"
      End Sub

      Public Sub LabelClose
            Set rsLabels = Nothing
      End Sub

      Public Function labelGet(label_id)
            On Error Resume Next
            If not rsLabels.EOF Then
                  rsLabels.Find "LabelId = " & label_id
                  If rsLabels.EOF Then
                        labelGet = "|Label Missing|"
                        labelGet = rsLabels.Fields("Text")
                  End If
                  labelGet = "|LabelPage Missing|"            
            End if
            If Err <> 0 Then
                  labelGet = "| labelGet Error: " & Err.Num & " / " & Err.Description &" |"
            End If
            On Error Goto 0 ' disables error handling enabled at start of function
      End Function

<!-- LABEL CODE END --->

      strCompanyLoginName = Request.Querystring
      If Len(strCompanyLoginName) > 0 Then
      ptr = InStr(strCompanyLoginName,"&lc=")
      If ptr > 0 Then
            strLanguageCode = Mid(strCompanyLoginName,ptr+4,2)
            strCompanyLoginName = Mid(strCompanyLoginName,1,ptr-1)
            strLanguageCode = Null
      End If
      SqlQuery = "SELECT * FROM Companies WHERE (CustomLoginPage LIKE '%asp?" & strCompanyLoginName & "')"
    Set      obj = Server.CreateObject("ADODB.Command")
    obj.ActiveConnection = objConnection
    obj.CommandText = SqlQuery
    Set rs = obj.Execute
      If NOT rs.BOF Then
            strClientID = rs.fields.Item("CompanyID")
            strVersion = Trim(rs.fields.Item("STVersion"))
            If IsNull(strLanguageCode) Then
                  strLanguageCode = rs.fields.Item("LanguageCode")
                  If IsNull(strLanguageCode) Then
                        strLanguageCode = "en"
                        strLanguageCode = Trim(strLanguageCode)
                  End If
            End If
            Session("KCCVersion") = strVersion
            labelOpen "custom.asp", strLanguageCode
            Response.Redirect "elearning.asp"
      End If      
dim objLayout, objSecurity
Dim Title, sTCP

set objLayout = new clsLayout
set objSecurity = new clsSecurity

If Request.QueryString("refresh") <> "" Then
      call objSecurity.SignOut
End IF

<title><% =labelGet(0) %></title>
<script language="JavaScript" src="online/simplytracking/includes/gen_validatorv2.js" type="text/javascript"></script>
<style type=text/css>
      A:hover { COLOR: #006699 }
      A { COLOR: #000000 }
      #TM_NOTE {
            border: #FF9900 solid 1px;
<body bgColor="#29517B" topmargin="10" leftmargin="10" marginheight="0">

<div align="left"><img src="online/logos/<%=strClientID%>logoweb.jpg" > <BR>


<% LabelLang = "fr" %>
<% LabelPage = "custom.asp" %>


        <a href="#" onclick="<% call labelOpen(LabelPage,LabelLang) %>">CALL LABELOPEN FUNCTION</a>


  <td align="left"> <br>
    <div><FONT size="5" face="Verdana, Arial, Helvetica, sans-serif" color=#FFFFFF>
      <% =labelGet(1) %>
        </FONT> </div><br>

<div align="center">
<TABLE border=0 cellpadding=0 cellspacing=0>

<!-- #INCLUDE file="includes/customlogin/2012studentlogin.asp" -->

Question by:KnowledgeWare
    LVL 6

    Expert Comment


    Accepted Solution

    I figured this out. Ajax not needed. Using string functions to read in the parameters at top of page and load the page respectively.


    <% if strLanguageCode = "en" then
          dim location
          location = "custom.asp?"& strCompanyLoginName & "&lc=fr"
    &nbsp;&nbsp;<input type="button" value="French" onClick="document.location='<%=location%>'">

    <% else %>

    <% location = "custom.asp?"& strCompanyLoginName & "&lc=en" %>

    &nbsp;&nbsp;<input type="button" value="Anglais"  onClick="document.location='<%=location%>'">
    <% end if %>


    Author Closing Comment

    Figured it out, it works, no mixup of technologies

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    In my daily work (mainly using, I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
    International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now