using C# class in jscript

G

Guest

Hello,

I have the following problem:
I have a web project where I display an activeX control that displays
2D-graphs on an aspx-page. I use jscript to access and modify the properties
of the activeX-2D-control. In
codebehind, I use C# for the application logic (eg. the database access).
The query to the database retuns me an object of a C# class (called
DBResultSet) that contains all the data from the query. This data has then to
be visualized on the 2d-graph activeX control on the .aspx-page
Here comes my question now:
How can I access the properties & methods of the class DBResultSet to assign
them to arrays and objects in jscript.
I know that the activeX control and jscript work on the clientside and the
application logic (written in C#) runs on the server. But the activeX control
can only be accessed on the clientside and I need the data from the database
to be displayed in the activeX-control.

I hope, somebody can help

thanks in advance

RFS666
 
G

Grant Merwitz

Two thing that comes to mind.

1) XmlHttp. Why not use Ajax to request the data in an Xml Format, which
your JScript can read and and set your 2d-graph appropriately.

2) Alternately, your C# code can write the JavaScript on page load and use
the Class DBResultSet while doing so

HTH

-G
 
G

Guest

Wow, thanks for the quick answer.

I decided to try alternative 2.
I create a string that contains the whole script code, beginning with
<script=jscript> and ending with </script>. Then I use the
registerClientScriptBlock method to inject the string containing the
scriptcode into the aspx-page.
But I don't know how to use the DBResult class in this script block.
The DBResult class contains a string array and an object array, these two
things have to be assigned to jscript string arrays and object arrays. My
problem is, I don't know how to make the cross-language assignment in the
scriptblock.
I tried like this:
string script = "<script language=jscript>";
script += "function useResult() {";
script += "var result : DBResult =
nameOfTheProtectedVariableInCodeBehindOfTypDBResult"; // Error in this line
script += "}";
script +="</script>";
RegisterClientScriptBlock("scriptBlock", script);

But this doesn't work.
Do I have to import something or so?

Thanks.

RFS666
 
G

Grant Merwitz

You need to come out of your inverted comma's

Lets make a basic example.

Code Behind

private void Page_Load(object Sender, EventArgs e)
{
string str = "HELLO";
string MyScript = "";
MyScript = "<script language=jscript>";
MyScript += "alert(" + str + ");"; //Here i am coming out of the string
into the code
MyScript +="</script>";
RegisterClientScriptBlock("scriptBlock", MyScript);
}

the effect.
A popup box that says hello :)

So when your setting your script, remember to come out of the inverted
comma;s to start using your c# variables or methids.

Hope thats clear enough
 
G

Guest

Hello Grant,
thanks for you quick and patient help,

you helped me really a lot!

RFS666
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top