By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,837 Members | 1,206 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,837 IT Pros & Developers. It's quick & easy.

script language = "js", "jscript", "javascript", "vj#" What to use

P: n/a
Hello,

I would like to use variables with a type in jscript.NET.
I declare them as follows:
var x : double = 5.03;

This doesn't work in my script, that I write to the page in codebehind with
"registerClientScriptBlock" as follows:
string script = "<script language=jscript>";
script += "function test()";
script += ...
Page.RegisterClientScriptBlock("usefulName", script);

I can only use untyped variables like "var x = 5;" in these scripts what is
not useful for me.
For each function in the registered script block, I add an onclick-event to
a webcontrol button:
button1.Attributes.Add("OnClick", "return function1();");

This works when using the statement <script language="jscript"> in the
script block that I want to write to the page with
"Page.RegisterClientScriptBlock"

But when I change the script language to "js", the functions are not called
anymore when I click the corresponding buttons. An error message appears,
that an object does not exist. But with "js" as script language, I can use
variables with a type.
The same with the "vj#"-tag

With the one tag (vj#, js) , I can use variables with a type, but call no
functions,
with an other tag (jscript, the one I am using), I can call the functions,
but use no typed variables.
I need both "features", so I hope, somebody can tell me what I'm doing wrong.
As variables with a type are only available since jscript.NET, I don't know,
if
<script language="jscript"> specifies jscript.NET.

I hope somebody can help.

Thanks in advance & kind regards

RFS666
Nov 19 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
not sure if you are getting a bit confused abt the client side and server
side programming..

the jscript.net is for server side programming... the code should be either
in <script language=jscript runat=server> block or in a code behind page...
"RFS666" wrote:
Hello,

I would like to use variables with a type in jscript.NET.
I declare them as follows:
var x : double = 5.03;

This doesn't work in my script, that I write to the page in codebehind with
"registerClientScriptBlock" as follows:
string script = "<script language=jscript>";
script += "function test()";
script += ...
Page.RegisterClientScriptBlock("usefulName", script);

I can only use untyped variables like "var x = 5;" in these scripts what is
not useful for me.
For each function in the registered script block, I add an onclick-event to
a webcontrol button:
button1.Attributes.Add("OnClick", "return function1();");

This works when using the statement <script language="jscript"> in the
script block that I want to write to the page with
"Page.RegisterClientScriptBlock"

But when I change the script language to "js", the functions are not called
anymore when I click the corresponding buttons. An error message appears,
that an object does not exist. But with "js" as script language, I can use
variables with a type.
The same with the "vj#"-tag

With the one tag (vj#, js) , I can use variables with a type, but call no
functions,
with an other tag (jscript, the one I am using), I can call the functions,
but use no typed variables.
I need both "features", so I hope, somebody can tell me what I'm doing wrong.
As variables with a type are only available since jscript.NET, I don't know,
if
<script language="jscript"> specifies jscript.NET.

I hope somebody can help.

Thanks in advance & kind regards

RFS666

Nov 19 '05 #2

P: n/a
This is client side script. I don't know if possible but even though it
would run only if the browser has .NET installed. IMO stick to javascript
for client side scripting...

Found :

Although browsers support most JScript .NET features, the new features that
target the .NET Framework, class-based objects, data types, enumerations,
conditional compilation directives, and the const statement, are supported
only on the server-side. Consequently, you should use these features
exclusively in server-side scripts.

So it looks like this is javascript client side and Jscript.NET server
side...

--
Patrice

"RFS666" <RF****@discussions.microsoft.com> a écrit dans le message de
news:0D**********************************@microsof t.com...
Hello,

I would like to use variables with a type in jscript.NET.
I declare them as follows:
var x : double = 5.03;

This doesn't work in my script, that I write to the page in codebehind with "registerClientScriptBlock" as follows:
string script = "<script language=jscript>";
script += "function test()";
script += ...
Page.RegisterClientScriptBlock("usefulName", script);

I can only use untyped variables like "var x = 5;" in these scripts what is not useful for me.
For each function in the registered script block, I add an onclick-event to a webcontrol button:
button1.Attributes.Add("OnClick", "return function1();");

This works when using the statement <script language="jscript"> in the
script block that I want to write to the page with
"Page.RegisterClientScriptBlock"

But when I change the script language to "js", the functions are not called anymore when I click the corresponding buttons. An error message appears,
that an object does not exist. But with "js" as script language, I can use
variables with a type.
The same with the "vj#"-tag

With the one tag (vj#, js) , I can use variables with a type, but call no
functions,
with an other tag (jscript, the one I am using), I can call the functions,
but use no typed variables.
I need both "features", so I hope, somebody can tell me what I'm doing wrong. As variables with a type are only available since jscript.NET, I don't know, if
<script language="jscript"> specifies jscript.NET.

I hope somebody can help.

Thanks in advance & kind regards

RFS666

Nov 19 '05 #3

P: n/a
Ok,

thanks for your replies. Now, I'm sure, that I use clientside scripting.
The codebehind file is in C#, but I've read that this is also called
"serverside scripting". This is very confusing for me, as I didn't consider
C# as a scripting language. I think it depends on the perspective. I should
mention that this is my first project with a scripting language. Ok, let's
go...

There are three ways to use clientside script (I think):
in <script> </script> block in an aspx-page or in a separate .js-file with
<script src="filename.js"> (in the aspx-page too) or dynamically created in
codebehind with Page.RegisterClientScriptBlock or Page.RegisterStartupScript.
I use the second and the third.

The third brings me to the following problem.
I need a double value in a jscript-variable, whose value I comes from a
codebehind double-value as follows.
script += "<script language=jscript>"
.....
script += "var aDouble = " + "\"" + aDoubleFromCodbehind + "\"" + ";";
.....
Page.RegisterClientScriptBlock("usefulName", script);

The problem is, that this assignment implicitly casts the double value that
comes from codebehind to a string. If I omit the two "\"", I receive an error
message on page_load:
Error: identifier expected

I also tried a conversion with:
script += "var aDouble = (Number)" + "\"" + aDoubleFromCodebehind + "\"" +
";";
but this gives me the following error message:
Error: ';' expected.

I can't believe, that explicit casting is not possible at client side.

So, I hope, somebody can bring some clearance into this

Thanks in advance & best regards

RFS666

Nov 19 '05 #4

P: n/a
If your double value holds 2.5 you'll want to create the following ligne :

var aDouble=2.5;

So just suppress the double quotes for a start...

--
Patrice

"RFS666" <RF****@discussions.microsoft.com> a écrit dans le message de
news:C6**********************************@microsof t.com...
Ok,

thanks for your replies. Now, I'm sure, that I use clientside scripting.
The codebehind file is in C#, but I've read that this is also called
"serverside scripting". This is very confusing for me, as I didn't consider C# as a scripting language. I think it depends on the perspective. I should mention that this is my first project with a scripting language. Ok, let's
go...

There are three ways to use clientside script (I think):
in <script> </script> block in an aspx-page or in a separate .js-file with
<script src="filename.js"> (in the aspx-page too) or dynamically created in codebehind with Page.RegisterClientScriptBlock or Page.RegisterStartupScript. I use the second and the third.

The third brings me to the following problem.
I need a double value in a jscript-variable, whose value I comes from a
codebehind double-value as follows.
script += "<script language=jscript>"
....
script += "var aDouble = " + "\"" + aDoubleFromCodbehind + "\"" + ";";
....
Page.RegisterClientScriptBlock("usefulName", script);

The problem is, that this assignment implicitly casts the double value that comes from codebehind to a string. If I omit the two "\"", I receive an error message on page_load:
Error: identifier expected

I also tried a conversion with:
script += "var aDouble = (Number)" + "\"" + aDoubleFromCodebehind + "\"" +
";";
but this gives me the following error message:
Error: ';' expected.

I can't believe, that explicit casting is not possible at client side.

So, I hope, somebody can bring some clearance into this

Thanks in advance & best regards

RFS666

Nov 19 '05 #5

P: n/a
"RFS666" <RF****@discussions.microsoft.com> wrote in message
news:C6**********************************@microsof t.com...
I can't believe, that explicit casting is not possible at client side.
It's not - JavaScript (like VBScript) has only only type of variable:
variant.
So, I hope, somebody can bring some clearance into this


var dblTest1 = "100.12";
var dblTest2 = "10.1";

alert(parseFloat(dblTest1) * parseFloat(dblTest2));
Nov 19 '05 #6

P: n/a
I think, I found out what the problem with:
script += "var aDouble = " + aDoubleFromCodebehind + ";";
is:
After receiving the error message and starting the debug mode, I realized,
that the double value contains a comma instead of a point: 0,8 instead of
0.8. But the double variable in codebehind contains a point, so where comes
the comma from? I cannot influence it.
Could it have something to do with the codepage of the aspx-file?

Thanks & regards

RFS666
Nov 19 '05 #7

P: n/a
Don't worry was expected ;-) Now that I'm sure that you don't work with the
decimal point, let's proceed with the next step :

DoubleValue.ToString(System.Globalization.Curlture Info.InvariantCulture)
(of course you can do an import to shorten the expression).

It will write down the value with the decimal point instead of a comma.

The problem is that as soon as you write down values such as decimal and/or
date, the text representation depends on national settings. The default
culture is defined in the web.config file and is suitable for displaying
data unlike programming languages. The InvariantCulture allows to avoid
using the current national setting...

--
Patrice

"RFS666" <RF****@discussions.microsoft.com> a écrit dans le message de
news:83**********************************@microsof t.com...
I think, I found out what the problem with:
script += "var aDouble = " + aDoubleFromCodebehind + ";";
is:
After receiving the error message and starting the debug mode, I realized,
that the double value contains a comma instead of a point: 0,8 instead of
0.8. But the double variable in codebehind contains a point, so where comes the comma from? I cannot influence it.
Could it have something to do with the codepage of the aspx-file?

Thanks & regards

RFS666

Nov 19 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.