Accessing a class from cleint side code

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.

Matt.
Matt_UnsworthAsked:
Who is Participating?
 
sybeCommented:
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

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


- 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.


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

Cheers!!
0
 
Matt_UnsworthAuthor Commented:
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.

<SCRIPT LANGUAGE=vbscript>
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
MSFlexGrid1.FixedCols=0
MSFlexGrid1.FixedRows=1

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)
      next
else
      msgbox "Failed"
end if
End Sub
</SCRIPT>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.