Accessing a class from cleint side code

Posted on 2003-11-04
Last Modified: 2012-08-14
I have the following in my global.asa:

Dim x

Set Application("x") = Server.CreateObject("Something.clsSomthing")

End Sub

I have been calling this as follows from server side code:

SomeVar = Application("x").SomeMethod

Now I'm having to use client side script as I'm using an MSFlexgrid, so how do I access ("x") from the client side? Basically how can I get SomeVar = Application("x").SomeMethod to work in client side code.

Looking forward to your help.

Question by:Matt_Unsworth
LVL 28

Accepted Solution

sybe earned 200 total points
ID: 9677852
you should realize that your class is on the server, and your script is on the client.

There are 2 ways to do what you want:

- copy the class to client script wile loading the page

//simplest way: just get everything you might need in different clientside variables
myvar1 = '<%=Application("x").SomeMethod%>';
myvar2 = '<%=Application("x").SomeOtherMethod%>';

- use some asynchronic way to go to the server and fetch the value. Like XMLHTTP. Those methods are highly browser dependent.
XMLHTTP works in IE only. As do xml-dataislands.

LVL 21

Expert Comment

ID: 9678090
you would have to use the method described by sybe above.. or do a post to the server and execute the method.


Author Comment

ID: 9685846
mmmmmm…….. this is proving more difficult than I first thought.

What I’m trying to do is place a number in a texbox then click a button which does the following:

1) Convert texbox value to variable
2) Pass variable to my class
3) Return results in an MSFlexGrid

My code is below, but at the moment it’s going into error at:
AgreementSearchResult = <%=Application("x").SearchByAgreement(AgreementVar)%>

and returning the following:

An exception of type 'Response object: 006~ASP 0185~Missing Default property was not found for the object.’ Was not handled.

Sub cmdAgreementSearch_OnClick
Dim AgreementVar
Dim AgreementSearchResult

'  Control validation
If txtAgreementSearch.value = "" Then
Msgbox "ERROR: Please enter an agreement number"
Exit Sub
End If

' convert user id to string variable, password already converted
'AgreementVar = txtAgreementSearch.value

' Bring x from the server to client side
AgreementSearchResult = <%=Application("x").SearchByAgreement(AgreementVar)%>

'  Get an array back from the class and populate the MSFlexGrid with it
Dim i

MSFlexGrid1.Rows = UBound(AgreementSearchResult, 2) + 1
MSFlexGrid1.Cols = 11

msgbox "Rows = " & UBound(AgreementSearchResult, 2) + 1

' Assign headers
MSFlexGrid1.TextMatrix(0, 1) = "ID"
MSFlexGrid1.ColWidth(1) = 2000
MSFlexGrid1.TextMatrix(0, 2) = "Name"
MSFlexGrid1.ColWidth(2) = 2000
MSFlexGrid1.TextMatrix(0, 3) = "Agreement"
MSFlexGrid1.ColWidth(3) = 2000
MSFlexGrid1.TextMatrix(0, 4) = "Claim"
MSFlexGrid1.ColWidth(4) = 2000
MSFlexGrid1.TextMatrix(0, 5) = "Type"
MSFlexGrid1.ColWidth(5) = 2000
MSFlexGrid1.TextMatrix(0, 6) = "Category"
MSFlexGrid1.ColWidth(6) = 2000
MSFlexGrid1.TextMatrix(0, 7) = "Sub-Category"
MSFlexGrid1.ColWidth(7) = 2000
MSFlexGrid1.TextMatrix(0, 8) = "Department"
MSFlexGrid1.ColWidth(8) = 2000
MSFlexGrid1.TextMatrix(0, 9) = "Open Date"
MSFlexGrid1.ColWidth(9) = 2000
MSFlexGrid1.TextMatrix(0, 10) = "Close Date"
MSFlexGrid1.ColWidth(10) = 2000
MSFlexGrid1.TextMatrix(0, 11) = "Assigned To"
MSFlexGrid1.ColWidth(11) = 2000

' Set grid's width (?)
'MSFlexGrid1.width = MSFlexGrid1.ColWidth(0) + MSFlexGrid1.ColWidth(1) + MSFlexGrid1.ColWidth(2) + MSFlexGrid1.ColWidth(3) + MSFlexGrid1.ColWidth(4) + MSFlexGrid1.ColWidth(5)

if UBound(AgreementSearchResult) > 0 then
      'call Populate_Array x
      for i = 1 to Ubound(AgreementSearchResult, 2)
            MSFlexGrid1.TextMatrix(i, 0) = TestArray(1, i)
            MSFlexGrid1.TextMatrix(i, 1) = TestArray(2, i) & " " & TestArray(3, 1) & " " & TestArray(4, 1)
            MSFlexGrid1.TextMatrix(i, 2) = TestArray(11, i)
            MSFlexGrid1.TextMatrix(i, 3) = TestArray(12, i)
            MSFlexGrid1.TextMatrix(i, 4) = TestArray(13, i)
            MSFlexGrid1.TextMatrix(i, 5) = TestArray(14, i)
            MSFlexGrid1.TextMatrix(i, 6) = TestArray(15, i)
            MSFlexGrid1.TextMatrix(i, 7) = TestArray(23, i)
            MSFlexGrid1.TextMatrix(i, 8) = TestArray(16, i)
            MSFlexGrid1.TextMatrix(i, 9) = TestArray(17, i)
            MSFlexGrid1.TextMatrix(i, 10) = TestArray(22, i)
      msgbox "Failed"
end if
End Sub

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

914 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

17 Experts available now in Live!

Get 1:1 Help Now