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

Discussion in 'ASP .Net' started by =?Utf-8?B?UkZTNjY2?=, Oct 27, 2005.

  1. 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
     
    =?Utf-8?B?UkZTNjY2?=, Oct 27, 2005
    #1
    1. Advertising

  2. 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
    >
    >
     
    =?Utf-8?B?U3JlZWppdGggUmFt?=, Oct 27, 2005
    #2
    1. Advertising

  3. =?Utf-8?B?UkZTNjY2?=

    Patrice Guest

    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" <> a écrit dans le message de
    news:...
    > 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
    >
    >
     
    Patrice, Oct 27, 2005
    #3
  4. 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
     
    =?Utf-8?B?UkZTNjY2?=, Oct 28, 2005
    #4
  5. =?Utf-8?B?UkZTNjY2?=

    Patrice Guest

    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" <> a écrit dans le message de
    news:...
    > 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
    >
     
    Patrice, Oct 28, 2005
    #5
  6. 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
     
    =?Utf-8?B?UkZTNjY2?=, Oct 28, 2005
    #6
  7. =?Utf-8?B?UkZTNjY2?=

    Mark Rae Guest

    "RFS666" <> wrote in message
    news:...

    > 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));
     
    Mark Rae, Oct 28, 2005
    #7
  8. =?Utf-8?B?UkZTNjY2?=

    Patrice Guest

    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.CurltureInfo.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" <> a écrit dans le message de
    news:...
    > 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
     
    Patrice, Oct 28, 2005
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon Maz
    Replies:
    4
    Views:
    1,273
    Jon Maz
    Sep 9, 2004
  2. =?Utf-8?B?cGVycGVy?=
    Replies:
    1
    Views:
    852
    Patrice
    Mar 22, 2005
  3. Maxwell2006
    Replies:
    5
    Views:
    2,394
    Steven Cheng[MSFT]
    Mar 7, 2006
  4. John Bentley
    Replies:
    14
    Views:
    352
    Jim Ley
    Feb 5, 2004
  5. VK
    Replies:
    4
    Views:
    355
    Thomas 'PointedEars' Lahn
    Jan 12, 2006
Loading...

Share This Page