Link to home
Start Free TrialLog in
Avatar of aelatik
aelatikFlag for Netherlands

asked on

ActiveX & ASP interaction

Hi,

I know how to build controls and use it in VB but what i need to know is how to pass data from an activeX control to a webpage.

For example i have an ActiveX control containing a Richt Textbox.
How can i store the content of the RichtTextbox to a database ( serverside ).

all i need to know is how to pass the data back to HTML/ASP ( not how to process it against the database )

PSEUDO CODE :

<%

      If Request("UserControl1") <> "" then <<< This is what i need to know
            ' Store the richttextcontent in the database
      end if

<HTML>
<HEAD>
</HEAD>
<BODY>
<OBJECT ID="UserControl1"
CLASSID="CLSID:5C769028-F430-4243-B9F6-FB69904BCCE0"
CODEBASE="Project1.CAB#version=1,0,0,0">
</OBJECT>
</BODY>
</HTML>
Avatar of EDDYKT
EDDYKT
Flag of Canada image

From your OCX, you can use event
ie

Public Event SendMessage(ByVal Mess As String)

some where in the code

you can call

RaiseEvent SendMessage("your richtextbox string here"


In your asp
Sub UserControl1_SendMessage(message)
      
On Error Resume Next

' to pass data back to server
XMLDoc1.src = "Serverside.asp?MESSAGE=" & message
End Sub

<BODY>

<xml type="text/xml" src="" id=XMLDoc1></xml>
....
</Body>Serverside.asp


You can write the string back to database by using Serverside.asp
Avatar of aelatik

ASKER

EDDYKT, I used the following :

AX Control >>>
---------------------------------------------------------------------------------------------------------------------------------
Public Event SendMessage(ByVal Mess As String)

Private Sub Command1_Click()
    RaiseEvent SendMessage(RichTextBox1.TextRTF)
End Sub
---------------------------------------------------------------------------------------------------------------------------------

ASP Page >>>
---------------------------------------------------------------------------------------------------------------------------------
<HTML><HEAD></HEAD><BODY>
<xml type="text/xml" src="" id=XMLDoc1></xml>
<OBJECT ID="UserControl1"
CLASSID="CLSID:5C769028-F430-4243-B9F6-FB69904BCCE0"
CODEBASE="Project1.CAB#version=1,0,0,0">
</OBJECT>
<script language="VBSCRIPT">
Sub UserControl1_SendMessage(message)
XMLDoc1.src = "Serverside.asp?MESSAGE=" & message
End Sub
<SCRIPT></BODY></HTML>
---------------------------------------------------------------------------------------------------------------------------------

This does not work, nothing happens ???
ASKER CERTIFIED SOLUTION
Avatar of EDDYKT
EDDYKT
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of aelatik

ASKER

OK, The messagebox gets triggered. But Serverside.asp is NOT.

This is what i have put temporarily in serverside.asp

<%

    Dim FSO, TEXTSTREAM
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    Set TEXTSTREAM = FSO.CreateTextFile("c:\file.txt", True, False)
          TEXTSTREAM.WriteLine (Request("MESSAGE"))
    Set TEXTSTREAM = Nothing
    Set FSO = Nothing
%>
Try this on Serverside.asp

<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
Dim FSO, TEXTSTREAM, str
    Set FSO = Server.CreateObject("Scripting.FileSystemObject")
    Set TEXTSTREAM = FSO.CreateTextFile("c:\file.txt", True, False)
    str = Request.QueryString("MESSAGE")
          TEXTSTREAM.WriteLine (str)
    Set TEXTSTREAM = Nothing
    Set FSO = Nothing
    Response.Write "<DATA>" & str & "</DATA>"
</SCRIPT>



Add this on the first asp file inside the script tag

Sub XMLDoc1_onreadystatechange()
      Dim ResponseStr
      
      On Error Resume Next
      If XMLDoc2.readyState = "complete" Then
                      msgbox  XMLDoc1.XMLDocument.xml
      End If
End Sub


This way you will see the message loop back to your html page
Correction

Sub XMLDoc1_onreadystatechange()
     Dim ResponseStr
     
     On Error Resume Next
     If XMLDoc2.readyState = "complete" Then
                      msgbox  XMLDoc1.XMLDocument.xml
     End If
End Sub


to


Sub XMLDoc1_onreadystatechange()
     
     On Error Resume Next
     If XMLDoc1.readyState = "complete" Then
        msgbox  XMLDoc1.XMLDocument.xml
     End If
End Sub
Avatar of aelatik

ASKER

Still nothing, serverside.asp is not triggered.
Are they in the same directory?
Can you also post the first asp file
Try to do the sample test


on the first asp

<html>

<head>
</head>
<SCRIPT LANGUAGE=VBScript>
sub button_onclick()
XMLDoc1.src = "Serverside.asp?MESSAGE=" & "message"
end sub

Sub XMLDoc1_onreadystatechange()
     
     On Error Resume Next
     If XMLDoc1.readyState = "complete" Then
        msgbox  XMLDoc1.XMLDocument.xml
     End If
End Sub

</SCRIPT>
<body>

<xml type="text/xml" src="" id=XMLDoc1></xml>
<input type="button" value="Button" id="button" name="B3"></p>

</body>

</html>


on the second asp

<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
    Dim str
   
    str = Request.QueryString("MESSAGE")
    Response.Write "<DATA>" & str & "</DATA>"
</SCRIPT>


This works for me
Avatar of aelatik

ASKER

I pasted exactly what you post above. Still nothing

Try it : http://www.knowledgexchng.com/sample
It works for me, I see the message box.

You can change some message on the second asp, and see whether i can read it

8->
Avatar of aelatik

ASKER

This is the second page :

<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
    Dim str
   
    str = Request.QueryString("MESSAGE")
    Response.Write "<DATA>" & str & "</DATA>"
</SCRIPT>

It's supposed to do a response.write
I said I click on your link and click the button

I see the message with

<DATA>message</DATA>

on the msgbox. You said you don't have msgbox coming up?
Avatar of aelatik

ASKER

I have a messagebox comming up, that is not the problem.
The problem is passing the data in the messagebox to serverside.asp
wait a minute, if you see the message

 <DATA>message</DATA>

on the messagebox, that means the serverside.asp has been call the return the string you pass from the first ASP. Do I miss something here?

Sub XMLDoc1_onreadystatechange()
     
     On Error Resume Next
     If XMLDoc1.readyState = "complete" Then
        msgbox  XMLDoc1.XMLDocument.xml
     End If
End Sub

The above routine is call the server side to your XML data island. That mean your serverside.asp has been called.
Avatar of aelatik

ASKER

You are right, i changed is to <test> and indeed the serverside.asp file is triggered.
But why is it running local instead of server ? Response.write should not give messageboxes ?
>>Response.write should not give messageboxes ?

you are right

However, this does

Sub XMLDoc1_onreadystatechange()
     
     On Error Resume Next
     If XMLDoc1.readyState = "complete" Then
        msgbox  XMLDoc1.XMLDocument.xml         '''''' this does
     End If
End Sub


The response.write actually write the data (message) back to XML data island and you display message box on the client side
That is one way you don't have to reload the entire asp instead use XML data island to perform as a bridge between client and server
Avatar of aelatik

ASKER

Im going to try an insert with ADODB serverside.
Avatar of aelatik

ASKER

OK, i tested it. What happens is as follows :

The first page shows a messagebox containing the parsed results from serverside.asp.
The ADODB Instert command on the serverside page does not fire.

This is serverside now ( which does not work ) :

<SCRIPT LANGUAGE=VBScript RUNAT=SERVER>
      Dim DS, str
          DS = "dsn=MYDSN;"
      str = Request.QueryString("MESSAGE")
      set RS= Server.CreateObject("ADODB.Command")
      RS.ActiveConnection = DS
      RS.CommandText = "INSERT INTO TABLENAME (FIELDNAME) VALUES ('" & str & "')"
      RS.CommandType = 1
      RS.CommandTimeout = 0
      RS.Prepared = true
      RS.Execute()
</SCRIPT>
You may want to debug your code and see what's the problem

ie

on error resume next
str = Request.QueryString("MESSAGE")
     set RS= Server.CreateObject("ADODB.Command")
if (err.number) then
response.write err.number  & "  " & err.description
endif
     RS.ActiveConnection = DS
     RS.CommandText = "INSERT INTO TABLENAME (FIELDNAME) VALUES ('" & str & "')"



etc
Is it a security problem?
Any luck?
Avatar of aelatik

ASKER

Its weird, no error is raised ??
Does your server side code works from VB. If yes, then mostly likely is security
Avatar of aelatik

ASKER

EDDYKT,

I do not have much time left to spend on this Q. I will get back to it in the future within a new question ofcourse.
Anyways, thanks for the effort...