-1

I have a label and I stored value from it through backend coding. I want to get the value of label and pass to Javascript. Please Help me. Everything works find but when I add update panel they now showing 0 value. I need to put update panel so that the page won't refresh every gridview row clicked.

Here is what I have so far.

 <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>

JavaScript

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

       }
       function pageLoad() {
            alert(pie)
           }

BackEnd

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
x'tian
  • 734
  • 2
  • 14
  • 40

1 Answers1

0

That's because you are putting the Gridview in different Update panel. Try putting the Label & Gridview in same Updatepanel

UPDATE

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

OR add trigger to the first UpdatePanel like below

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
        <asp:Label ID="my_graph" runat="server"></asp:Label>
    </ContentTemplate>
    <Triggers>
         <asp:AsyncPostBackTrigger ControlID="Gridview_1" EventName="SelectedIndexChanged" />
    </Triggers>
</asp:UpdatePanel>
jonju
  • 2,711
  • 1
  • 13
  • 19
  • Its now throwing error " Could not find an event named 'Gridview1_OnSelectedIndexChanged' on associated control 'GridView1' for the trigger in UpdatePanel 'UpdatePanel1'." – x'tian Aug 02 '16 at 05:38
  • I have a lot of gridview and Im storing the gridview row clicked value to just one label. What I want to know is to pass the label value to javascript to display in pie chart. Also I tried the sample you gave but its not working. Do you have any idea? Im so lost. – x'tian Aug 02 '16 at 05:58
  • try to call the javascript function on `onClientClick` event of the row then – jonju Aug 02 '16 at 06:00
  • Can you please teach me how? I don't have any idea. Tried a lot of workaround still no luck. – x'tian Aug 02 '16 at 06:02