Asp label value to pass in javascript

I have a label in which displaying a value from database. Everything works find but when I put update panel to avoid the page refresh every row clicked in gridview the variable is showing zero value. What I want to achieve is to pass the value of label in JavaScript variable.

Here is my sample code:

Front End

> <asp:UpdatePanel ID="UpdatePanel1" runat="server">
>  <ContentTemplate>
>  <asp:Label ID="my_graph" runat="server"></asp:Label>
>  </ContentTemplate>
>  </asp:UpdatePanel>

> <asp:UpdatePanel ID="UpdatePanel4" runat="server">
> <ContentTemplate>
> <asp:GridView ID="GridView1" class = "grd-view table table-hover" OnRowDataBound="GridView1_RowDataBound"  OnSelectedIndexChanged="Gridview1_OnSelectedIndexChanged"  runat="server">
> </asp:GridView>                                                
> </ContentTemplate>
> </asp:UpdatePanel>

> <div id="chartContainer" style="height: 150px; width: 100%;"></div>

Back End

Protected Sub Gridview1_OnSelectedIndexChanged(sender As Object, e As EventArgs) Handles GridView1.SelectedIndexChanged

        Dim percent As String = GridView1.SelectedRow.Cells(6).Text
        my_graph.Text = percent

        ClientScript.RegisterClientScriptBlock(Me.[GetType](), "Script", "changepie(" + my_graph.Text + ");", True)

    End Sub

JavaScript

 var pie = 0;
       function changepie(val) {
       pie = val;

       }
       function pageLoad() {
            alert(pie)
           }

What does the front end code look like in the web browser - that’s what the JavaScript will interact with.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.