Solved

Accessing a class from cleint side code

Posted on 2003-11-04
3
309 Views
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.

Matt.
0
Comment
Question by:Matt_Unsworth
3 Comments
 
LVL 28

Accepted Solution

by:
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

<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
 
LVL 21

Expert Comment

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

Cheers!!
0
 

Author Comment

by:Matt_Unsworth
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.

<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

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
This video discusses moving either the default database or any database to a new volume.

758 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

23 Experts available now in Live!

Get 1:1 Help Now