Bader
Bader

Reputation: 3774

How to keep the values of checkboxes after postback in asp.net?

I have a checkbox in datalist, after the button is clicked(postback) the value of checkbox is cleared. For example, if the checkbox in datalist is checked, when the button is clicked the checkbox appears unchecked when getting it's value

Upvotes: 0

Views: 3826

Answers (2)

TheGeekYouNeed
TheGeekYouNeed

Reputation: 7539

I bet that you are binding your DataList incorrectly.

You need to check if Not Page.IsPostBack, and bind in there. Otherwise, you are binding every postback and resetting all values.

Upvotes: 0

Vinod
Vinod

Reputation: 4882

Try this:

Put your databinding code in Page load inside

If (!IsPostBack)
{
     //Bind  Data 
} 

Upvotes: 1

Related Questions