Q:

Why label text is getting changed after clicking on asp.net button?

I have a WebForm ASP label and button. I am setting the label's value on page load. For example, the label text on page load is 2 items selected. This comes from the database. Then if the user changes the selection then it counts the selected values by jQuery and sets the text as 5 items selected. 
When I click on the submit button to save changes, again it resets to 2 items selected. I didn't use an update panel. I don't know what is going on here. Can anyone please explain this scenario?
$("#lblCount").text($('#grdProducts').find('input#chkSelect:checked').length + ' Complementary Products added');

C# on page load:  
lblCount.Text = ComplementaryproductCount.ToString() + " Complementary Products added";

I do not understand why the label text is changed on button click. I couldn't find anything while debugging too.  
Thanks

A:

When you set lblCount.Text in your code, that value is set into the ViewState of the page... that means when your page is posted back to the server (to handle an event, etc) ASP.Net knows what lblCount.Text was originally and can re-render the HTML with the same value.
As part of that post-back to the server, the browser will send back that ViewState along with any input control values (things like textboxes, dropdowns, hidden field).
What it does NOT do is post-back any changes you might have made to the elements on the page via things like jQuery (other than input controls I mentioned above).
The result is that although you've changed the element on the screen, the server knows absolutely nothing about that change, and it will re-send the original HTML for the label back to the browser.
Your only option is to do something as suggested by @John in his comment... you need to store the fact the element has changed in an input, and then use that.
For instance...
<asp:Label runat="server" id="lblCount" />
<asp:HiddenField runat="server" id="hdnCount" />

function updateCount(newCount) {
  $("#<%=lblCount.ClientID%>").text("Count: " + newCount.toString());
  $("#<%=hdnCount.ClientID%>").val(newCount.toString());
}

Then in your code-behind you can have...
if (!Page.IsPostBack)
{
   var count = 1;
   lblCount.Text = String.Format("Count: {0}", count);
   hdnCount.Value = count.ToString();
}
else
{
   lblCount.Text = String.Format("Count: {0}", hdnCount.Value);
}

