简体   繁体   中英

Pass vales from Javascript back to C# function

I am using the following snippet in my Javascript -

plotOptions: {
    series: {
        cursor: 'pointer',
        point: {
            events: {
                click: function() {
                    hs.htmlExpand(null, {
                        pageOrigin: {
                            x: this.pageX,
                            y: this.pageY
                        },
                        headingText: this.series.name,
                        maincontentText: 
                                'Value1:' + this.x +
                                ' Value2:' + this.y,
                        width: 300
                    });
                }
            }
        },
        marker: {
            lineWidth: 1
        }
    }
},

This is part of a function that generates a graph and when a user clicks on a point on the graph, the previous code will load up a popup with the values this.x and this.y as the body text.

However once the point has been clicked, I need to pass this.x and this.y back to the C# to use in a function.

I tired to makes 2 variables at the top of the function: var X and var Y and then set them in the function when the point is clicked like -

 headingText: this.series.name,
 maincontentText: 
 'Value1:' + this.x +
 ' Value2:' + this.y,
 width: 300
 X = this.x
 Y = this.y

However adding that broke the function with the error-

Error: 'chart' is undefined

I believe the solution might be as simple as missing comma(s).

 headingText: this.series.name,
 maincontentText: 
 'Value1:' + this.x +
 ' Value2:' + this.y,
 width: 300,
 X = this.x,
 Y = this.y

You can add two text box and set display:none;

and then set the value of text box from X and Y and Use them from code behind

var x  = this.x;
var y  = this.y; 
$('#TextBox1').val($('#TextBox1').val().replace($('#TextBox1').val(), x));
$('#TextBox2').val($('#TextBox2').val().replace($('#TextBox2').val(), y));

Saparate values with comma(,).

width: 300,
 X = this.x,
 Y = this.y

you have missed the comma thats why its giving error.

The problem is that you are messing variables with options for expander. This is proper code:

           click: function() {

                window.X = this.x;
                window.Y = this.y;

                hs.htmlExpand(null, {
                    pageOrigin: {
                        x: this.pageX,
                        y: this.pageY
                    },
                    headingText: this.series.name,
                    maincontentText: 
                            'Value1:' + this.x +
                            ' Value2:' + this.y,
                    width: 300
                });
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM