CSharp/C# >> converting js file into dll

by rizjabbar » Tue, 10 Jun 2008 03:51:05 GMT

I have a js file that is being accessed through an html page. This
requirement is not going to change.
At this time, a need has arisen for access to the functions of these
files from another program that is running in C# / .Net environmet. Is
there any way to convert this file from a js file to dll.
I have access to all the three codes, the only requirement is that we
want to maintain one version of the js file.

Here is an example of the working code:
a) HTML calling code
<html>
<head>
<SCRIPT LANGUAGE="JavaScript" SRC="TEng.js" ></SCRIPT>
</head>
<body>
<script type="text/javascript">
var fst = 10;
var snd = 10000;
var p = new InitEngine(fst);
document.write('<BR> random: ' + p.EngineRank(snd) );
</script>
</body>
</html>

b) "TEng.js" file
function InitEngine(diObj)
{
// initialize the member variables for this instance
this.piObj = diObj;

// initialize the member function references for the class
prototype
if (typeof(_InitEngine_prototype_called) == 'undefined')
{
_InitEngine_prototype_called = true;
InitEngine.prototype.EngineRank = EngineRank;
InitEngine.prototype.rndm = rndm;
}
////////////////////////////////////////////////////////////////////////////
function EngineRank(posObj)
{
var sTmp = this.rndm(posObj, this.piObj);
return sTmp;
}

function rndm(a, b)
{
return a + Math.floor(Math.random()*(b-a+1));
}
}
////-----------------------------------------------

Tried compiling the dll code with visual studio's jsc command but got
the following error.
TEng.js(7,24) : error JS1135: Variable '_InitEngine_prototype_called'
has not b
een declared
TEng.js(1,9) : error JS1234: Only type and package definitions are
allowed insid
e a library


CSharp/C# >> converting js file into dll

by Dan Rumney » Tue, 10 Jun 2008 04:05:52 GMT



[snip]

Try declaring _InitEngine_prototype_called:
var _InitEngine_prototype_called = true;

CSharp/C# >> converting js file into dll

by rizjabbar » Tue, 10 Jun 2008 04:51:51 GMT

You are right: I was thinking that I needed it to be undefined... but
change the basic logic and keep the initialization process in touch.
This resolved one of the two issue. Here are the changes.
var _InitEngine_prototype_called = false;
if (_InitEngine_prototype_called == false)

Still getting the second errorJS1234: Only type and package
definitions are allowed inside a library

Similar Threads

1. Using .js files rather than embedded js

I am trying to migrate from lots of javascript embedded within an aspx file 
to using .js files.

So far no luck.  I have created the .js file which contains part of the 
javascript which was part of the aspx file and worked correctly.

First it seems that I cannot get what should exist in the .js file.  I 
assume although finding real examples on the net is more difficult than I 
thought.  My .js file contains 3 functions.  There is no script tag.

I then (although I have tried the RegisterClientScriptBlock method) to 
simply put the following into the <head

<script src="ZipFileHandling.js" type="text/javascript" 
language="javascript"></script>

Now when I run I get that wonderful "A Runtime Error has occured. Do you 
wish to debug?  Line 3 Error Syntax error".  Of course what is line 3????

Right now I am stuck.

Thanks
Lloyd Sheen 

2. converting a c++ file to a .dll file - Windows XP

3. Master Pages using JavaScript.js file

Hi,

I want to incorporate a JavaScript routine (found on the internet) in my 
page that will restore the scrollbar position of a div tag on postback.  I am 
using master pages which complicates things and also want to reference the 
script via a ".js" file.  Below is the code I have come-up with but it 
doesn't work (I get a blank screen).  The script is located in the project 
folder in the JavaScript folder.  Any ideas?

Thanks,
Jeff


        Page.RegisterClientScriptBlock("MyScript", "<script 
language=javascript src='JavaScript/sscroller.js'>"); 

4. Add a .js file to an aspx using inheritance - CSharp/C#

5. Using js file in asp.net 2.0

Hi,

I simply wish to code a JS function ONCE, in a .js file, include the .js 
file in the Master page, and then in several but not all pages, I wish to 
execute the function on pageload.

I don't want to use the
Page.ClientScript.RegisterStartupScript(this.GetType(),"displaymessage", 
strScript, false);

method because this seemingly requires me to code the JScript on all the 
pages (code behind) where I want to run the function, which is stupid.



I think what I want to use is something like :



Designate the body tag as :

<body runat="server" id="body">

and in the code behind for a particular page:

protected void Page_Load(object sender, EventArgs e)

{

    try

    {

        string temp = "displaymessage();";


        HtmlGenericControl body = 
(HtmlGenericControl)Master.FindControl("Body");

        body.Attributes.Add("onload", temp);

    }

    catch (NullReferenceException x)

    {

    Response.Write(x);

    }

}



but this give a JS error where it says 'Object Required' where the body tag 
is in the rendered html



It does work if I do:

protected void Page_Load(object sender, EventArgs e)

{

    try

    {

            string temp = "alert('Hello World!');";

             HtmlGenericControl body = 
(HtmlGenericControl)Master.FindControl("Body");

            body.Attributes.Add("onload", temp);

    }

    catch (NullReferenceException x)

    {

        Response.Write(x);

    }

}



So what is wrong?


6. Visual Studio only debugs javascript in .js files not .aspx files - Asp.Net

7. how to convert vb standard exe to DLL file programatically in c#

8. Converting an INI text file to a dll resource