Click here to Skip to main content
15,909,445 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi Developers,
In my Web application

I am setting the Hidden Field value in Jquery function.
And I am trying to access the hidden field value in code behind in c#.

But I am not getting the Hidden field value.

Please check the below code for my aspx page:

HTML
<html xmlns="http://www.w3.org/1999/xhtml">
<head  runat="server">
    <title></title>
    <link href="Styles/StyleSheet1.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="Styles/html2canvas.js"></script>
    <script type="text/javascript">
       
        function warningMessage() {
            var canvas1 = document.getElementById("myCanvas");
            html2canvas(document.getElementById("grvMergeHeader"), {


                onrendered: function (canvas1) {
                    //document.body.appendChild(canvas1);

                    var image = canvas1.toDataURL("image/png");
                    image = image.replace('data:image/png;base64,', '');
                    document.getElementById("hdnResultValue").value = image;
                }
            });
        }
    </script>
</head>
<body>
    <form id="form1"  runat="server">
    <div>
    <canvas id="myCanvas"  runat="server" width="200" height="200" hidden="hidden"></canvas>
    <asp:HiddenField ID="hdnResultValue" Value="Hie." runat="server" ClientIDMode="Static"/>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Export To PPT" Visible="False" />
      
           
        <asp:Button ID="Button2" runat="server" onclick="Button2_Click" Text="Button" OnClientClick="warningMessage();"/>
           
    <asp:GridView ID="grvMergeHeader" runat="server" CssClass="HeaderStyle" 
                            OnRowCreated="grvMergeHeader_RowCreated1"
                            OnRowDataBound="grvMergeHeader_RowDataBound" AllowSorting="True"
                            PageSize="25" AutoGenerateColumns="false" 
            ForeColor="White" Font-Names="Arial" Font-Size="10pt" GridLines="None">
                            <HeaderStyle Font-Bold="False" BorderWidth="0" />
                            <AlternatingRowStyle BackColor="White"  Font-Bold="false"   />
                          <Columns>
                                <asp:BoundField DataField="State" HeaderText="State"  ItemStyle-Width="5%" ItemStyle-HorizontalAlign="Left" ItemStyle-Height="3px" HeaderStyle-CssClass="ff1" />                                
                                <asp:BoundField DataField="LOB" HeaderText="LOB"  ItemStyle-Width="15%" ItemStyle-HorizontalAlign="Left" ItemStyle-Height="3px" HeaderStyle-CssClass="ff2" />
                                <asp:BoundField DataField="DPW" HeaderText="2012 DPW"  ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" DataFormatString="{0:0.00}" />
                                <asp:BoundField DataField="10Y_PremiumGrowth" HeaderText="Premium growth"  ItemStyle-Width="8%"   ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" DataFormatString="{0:0.00}" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="Prem_growth" />
                                <asp:BoundField DataField="10Y_OutperformUnderperform" HeaderText="Loss&LAE Incurred Out(Under) performance "  ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px"  HeaderStyle-CssClass="LossLAE10" />
                                <asp:BoundField DataField="5Y_PremiumGrowth" HeaderText=" premium growth " ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right"  ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="Prem_growth"  />
                                <asp:BoundField DataField="5Y_OutperformUnderperform" HeaderText=" Loss&LAE Incurred Out(Under) performance" ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="LossLAE5"/>
                                <asp:BoundField DataField="3Y_PremiumGrowth" HeaderText="premium growth " ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right"  ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="Prem_growth" />
                                <asp:BoundField DataField="3Y_OutperformUnderperform" HeaderText="Loss&LAE Incurred Out(Under) performance" ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right"  ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="LossLAE3"/>
                                <asp:BoundField DataField="10Y_LossLAERatio" HeaderText="10years" ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="yrs1035" />                             
                                <asp:BoundField DataField="5Y_LossLAERatio" HeaderText="5 years " ItemStyle-Width="8%"  ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px"  HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="yrs1035"/>
                                <asp:BoundField DataField="3Y_LossLAERatio" HeaderText="3 years " ItemStyle-Width="8%"   ItemStyle-HorizontalAlign="Right" ItemStyle-Height="3px" HeaderStyle-HorizontalAlign="Center" HeaderStyle-VerticalAlign="Bottom" HeaderStyle-CssClass="yrs1035"/>
                            </Columns>
                            <RowStyle BackColor="#c9c9c7"  Font-Size="10pt" Font-Names="Arial" ForeColor="Black" />
                        </asp:GridView>
                       
    </div>
        </form>
</body>
</html>


And My Code behind code:

C#
protected void Page_Load(object sender, EventArgs e)
        {
           
            if (!IsPostBack)
            {
                GetData();
            }
          
        }
public void GetData()
        {

            string lobgrouplist = "";
            try
            {
               
                if (Session["table"] == null)
                {
                    lobgrouplist = "";
                }
                else
                {
                    lobgrouplist = Convert.ToString(Session["table"]);
                   
                }

                string snlcompanyname = "Stonebridge Casualty Ins Co.";
                string reporttypeflag = "S";
                string snlstatelob = "All States";
                string foryears = "";
                string forperformance = "";


                DataTable dataTable = new DataTable();

                SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["LOUPe_Inventory_WorkingConnectionString"].ConnectionString);
                SqlCommand cmd = new SqlCommand("procWebLossRatioAnalysis_G_RP_LR", connection);
                SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(cmd);
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.AddWithValue("@pSNLCompanyName", snlcompanyname);
                cmd.Parameters.AddWithValue("@pReportTypeFlag", reporttypeflag);
                cmd.Parameters.AddWithValue("@pSNLStateLOB", snlstatelob);
                cmd.Parameters.AddWithValue("@pForYears", foryears);
                cmd.Parameters.AddWithValue("@pPerformance", forperformance);
                cmd.Parameters.AddWithValue("@pLOBGrpList", lobgrouplist);
                sqlDataAdapter.Fill(dataTable);
                grvMergeHeader.DataSource = dataTable;
                grvMergeHeader.DataBind();

            }
            catch
            {
                throw;
            }
            finally
            {
                conn.Close();
            }
        }
protected void Button2_Click(object sender, EventArgs e)
        {
            Button1.Visible = true;
          
            //Page.ClientScript.RegisterStartupScript(this.GetType(), "jh", "warningMessage();", true);

            string codeBehindValue= hdnResultValue.Value;
            
            grvMergeHeader.Visible = false;
        }


Please tell me what might be the problem and kindly provide me the solution
Posted
Updated 20-Oct-13 16:48pm
v5

1 solution

This is due to the underhanded post back, Try to place an update panel and try.
If it still wont work then reply to this. I have an alternate solution for that.
 
Share this answer
 
Comments
D-Kishore 17-Oct-13 5:58am    
you mean that I need to keep hidden field in UpdatePanel.
D-Kishore 17-Oct-13 6:14am    
Hi Hatim,

I used UpdatePanel, No success, kindly provide other way what you have.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900