OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

JS function vs C#

  • Thread starter Thread starter MART
  • Start date Start date
M

MART

Guest
I am quite new to JS and doing web apps and I am facing this problem: I have JS code which creates me 6 gauges and function which updates gauge 1 value:

Code:
<!-- Include the Gauge.js library -->
<!-- Raphael must be included before justgage -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.4/raphael-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/justgage/1.2.9/justgage.min.js"></script>
        <!-- Initialize the gauge on page load -->
    <script>
        var gauge1;
        var gauge2;
        var gauge3;
        var gauge4;
        var gauge5;
        var gauge6;

        function updateGaugeValue(newValue, event) {
            event.preventDefault();
            gauge1.refresh(newValue);
        }

        window.onload = function () {

            gauge1 = new JustGage({
                id: "gauge1",
                value: 0,
                min: 0,
                max: 10,
                title: "My Gauge",
                label: "Value"
            });

            gauge2 = new JustGage({
                id: "gauge2",
                value: 0,
                min: 0,
                max: 10,
                title: "My Gauge",
                label: "Value"
            });

            gauge3 = new JustGage({
                id: "gauge3",
                value: 0,
                min: 0,
                max: 10,
                title: "My Gauge",
                label: "Value"
            });

            gauge4 = new JustGage({
                id: "gauge4",
                value: 0,
                min: 0,
                max: 10,
                title: "My Gauge",
                label: "Value"
            });

            gauge5 = new JustGage({
                id: "gauge5",
                value: 0,
                min: 0,
                max: 10,
                title: "My Gauge",
                label: "Value"
            });

            gauge6 = new JustGage({
                id: "gauge6",
                value: 0,
                min: 0,
                max: 10,
                title: "My Gauge",
                label: "Value"
            });

        };

</script>

When I call update from button like this

Code:
<button onclick="updateGaugeValue(5, event)">Click me</button>

function normally works and change value of gauge 1 to 5. But when I try to call this function from C# (using ASP.NET) via ClientScript like:

Code:
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "updateGaugeValue(5, event)", true);

nothing happens. But if I try to test it and alert hello world like

Code:
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "alert('Hello World')", true);

it normally works and alert. Any suggestions? I expect that I am able to call this JS function from C# code.

<p>I am quite new to JS and doing web apps and I am facing this problem:
I have JS code which creates me 6 gauges and function which updates gauge 1 value:</p>
<pre><code><!-- Include the Gauge.js library -->
<!-- Raphael must be included before justgage -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/raphael/2.1.4/raphael-min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/justgage/1.2.9/justgage.min.js"></script>
<!-- Initialize the gauge on page load -->
<script>
var gauge1;
var gauge2;
var gauge3;
var gauge4;
var gauge5;
var gauge6;

function updateGaugeValue(newValue, event) {
event.preventDefault();
gauge1.refresh(newValue);
}

window.onload = function () {

gauge1 = new JustGage({
id: "gauge1",
value: 0,
min: 0,
max: 10,
title: "My Gauge",
label: "Value"
});

gauge2 = new JustGage({
id: "gauge2",
value: 0,
min: 0,
max: 10,
title: "My Gauge",
label: "Value"
});

gauge3 = new JustGage({
id: "gauge3",
value: 0,
min: 0,
max: 10,
title: "My Gauge",
label: "Value"
});

gauge4 = new JustGage({
id: "gauge4",
value: 0,
min: 0,
max: 10,
title: "My Gauge",
label: "Value"
});

gauge5 = new JustGage({
id: "gauge5",
value: 0,
min: 0,
max: 10,
title: "My Gauge",
label: "Value"
});

gauge6 = new JustGage({
id: "gauge6",
value: 0,
min: 0,
max: 10,
title: "My Gauge",
label: "Value"
});

};

</script>
</code></pre>
<p>When I call update from button like this</p>
<pre><code><button onclick="updateGaugeValue(5, event)">Click me</button>
</code></pre>
<p>function normally works and change value of gauge 1 to 5.
But when I try to call this function from C# (using ASP.NET) via ClientScript like:</p>
<pre><code>Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "updateGaugeValue(5, event)", true);
</code></pre>
<p>nothing happens. But if I try to test it and alert hello world like</p>
<pre><code>Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "alert('Hello World')", true);
</code></pre>
<p>it normally works and alert. Any suggestions? I expect that I am able to call this JS function from C# code.</p>
 

Latest posts

Z
Replies
0
Views
1
zuegelwagen
Z
Top