title: Refresh the session in Updatepanel on Partial Postback in ASp.net
body: <p>I have one Update panel &amp; in that update panel I have a session.</p>
  
  <p>On Partial post back I have to change the value of session depending on the Dates.
  But When I do the partial Postback session is not refreshed Or lost, Dont know . 
  On the button click I am changing the session values.
  How can I achieve that </p>
  
  <p><strong>Here Is the HTML</strong></p>
  
  <pre><code>        &lt;asp:UpdatePanel ID="UpdatePasanel1" 
             UpdateMode="Always"  
                 ClientIDMode="AutoID"ChildrenAsTriggers="true" runat="server"&gt;
             &lt;ContentTemplate&gt;
               &lt;div class="vendor_shift_top"&gt;
                &lt;div class="col-md-12"&gt;
                  &lt;div class="cntrol_heading"&gt;
  
  
  
              &lt;div class="inner_cntrol_heading_right"&gt;
  
                  &lt;div class="cls"&gt;
  
  
                      &lt;div class="popup_inner"&gt;
                          Start Date:
                      &lt;/div&gt;
  
  
                      &lt;div class="popup_inner"&gt;
  
                          &lt;asp:TextBox ID="txtStartDate" ReadOnly="false" AutoPostBack="false" CssClass="txt_80" runat="server"&gt;&lt;/asp:TextBox&gt;                                
                      &lt;/div&gt;
  
                      &lt;div class="popup_inner"&gt;
                          End Date:                                                    
                      &lt;/div&gt;
                      &lt;div class="popup_inner"&gt;
                          &lt;asp:TextBox ID="txtEndDate" ReadOnly="false" CssClass="txt_80" runat="server"&gt;&lt;/asp:TextBox&gt;                              
                      &lt;/div&gt;
                      &lt;div class="popup_inner"&gt;
                          &lt;asp:LinkButton ID="LinkButton1" ForeColor="White" OnClick="Button1_Click" runat="server"&gt;&lt;img src="../images/search.png" /&gt; Search&lt;/asp:LinkButton&gt;                               
                      &lt;/div&gt;
                  &lt;/div&gt;
  
  
                  &lt;script type="text/javascript"&gt;
                      //On Page Load
                      $(".cls1").click(function () {
                          $(".cls").toggle("blind", 100);
                      });
  
                      //On UpdatePanel Refresh
                      var prm = Sys.WebForms.PageRequestManager.getInstance();
                      if (prm != null) {
                          prm.add_endRequest(function (sender, e) {
                              if (sender._postBackSettings.panelsToUpdate != null) {
                                  $(".cls1").click(function () {
                                      $(".cls").toggle("blind", 100);
                                  });
                              }
                          });
                      };
                  &lt;/script&gt;
  
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  
      &lt;div class="vendor_shift_top"&gt;
          &lt;div class="col-md-12 map_box"&gt;
              &lt;script type="text/javascript" class="s"&gt;
                  //On Page Load
                  $(function () {
                      var dataSource = [
                              &lt;%=Session["TotalSalesPurchase"]%&gt;
                      ];
  
                      $("#chartContainer3").dxChart({
                          dataSource: dataSource,
                          commonSeriesSettings: {
                              argumentField: "year"
                          },
                          series: [
                              { valueField: "Inward", name: "Purchase" },
                              { valueField: "Outward", name: "Sales" },
                          ],
                          argumentAxis: {
                              grid: {
                                  visible: true
                              }
                          },
                          tooltip: {
                              enabled: true
                          },
                          legend: {
                              verticalAlignment: "bottom",
                              horizontalAlignment: "center"
                          },
                          commonPaneSettings: {
                              border: {
                                  visible: true,
                                  right: false
                              }
                          }
                      });
                  });
  
                  //On UpdatePanel Refresh
                  //var prm = Sys.WebForms.PageRequestManager.getInstance();
                  //if (prm != null) {
                  Sys.WebForms.PageRequestManager.getInstance().add_endRequest(function (sender, e) {
                      //if (sender._postBackSettings.panelsToUpdate != null) {
  
                      var dataSource = [
                              &lt;%=Session["TotalSalesPurchase22"]%&gt;
                      ];
  
                      $("#chartContainer3").dxChart({
                          dataSource: dataSource,
                          commonSeriesSettings: {
                              argumentField: "year"
                          },
                          series: [
                              { valueField: "Inward", name: "Purchase" },
                              { valueField: "Outward", name: "Sales" },
                          ],
                          argumentAxis: {
                              grid: {
                                  visible: true
                              }
                          },
                          tooltip: {
                              enabled: true
                          },
                          legend: {
                              verticalAlignment: "bottom",
                              horizontalAlignment: "center"
                          },
                          commonPaneSettings: {
                              border: {
                                  visible: true,
                                  right: false
                              }
                          }
                      });
                      //}
                  });
                  //};
              &lt;/script&gt;
              &lt;div id="chartContainer3" 
             class="overlap_cls" runat="server" style="width: 100%; height: 340px;"&gt;&lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
       &lt;/ContentTemplate&gt;
        &lt;Triggers&gt;
           &lt;asp:AsyncPostBackTrigger ControlID="LinkButton1" EventName="Click" /&gt;
        &lt;/Triggers&gt;
    &lt; /asp:UpdatePanel&gt;
  </code></pre>
  
  <p><strong>C#</strong></p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
      {
          //Session.Remove("TotalSalesPurchase22");
  
          cm.ds.Clear();
          ArrayList arr = new ArrayList();
          arr.Add("@StartDate|" + txtStartDate.Text + "");
          arr.Add("@EndDate|" + txtEndDate.Text + "");
          cm.sp_reader_execute("spSalesPurchase_LineChart_Order", arr);
  
          string DisplayChartFormat = "";
          while (cm.rs.Read())
          {
              string MonthYear = cm.rs["month"].ToString() + "-" + cm.rs["year"].ToString();
              DisplayChartFormat += "{ year: '" + MonthYear + "', Inward: " + cm.rs["InWardQty"].ToString() + ", Outward: " + cm.rs["OutWardQty"].ToString() + " },";
          }
  
          string FinalDisplayFormat = DisplayChartFormat.Remove(DisplayChartFormat.Length - 1);
          Session["TotalSalesPurchase22"] = FinalDisplayFormat;
          ScriptManager.RegisterStartupScript(this.UpdatePanel1, typeof(string), "alertScript", string.Format("alert('{0}');", Session["TotalSalesPurchase22"]), true);
      }
  </code></pre>
  
  <p>Any Help will be appreciated </p>
  
  <p>Thank You</p>
  
  <p>Hardik Parmar.</p>