jeudi 17 mars 2016

Preventing AutoPostBack from resetting my page (C# and ASP.net) and CheckedChanged problems

I am building a page that includes some components that are static on the page (dropdowns, buttons, a table to hold them in), but one table cell is filled with variably generated CheckBoxes. When a button is pressed, the code for the page calculates what checkboxes to place and creates a new CheckBox object for each one needed and then adds it to an existing Div on the page.

I am trying to trigger some code to run when any of these are checked or unchecked, but checkBoxName.CheckedChanged += cbCheckedChanged wasn't working. I researched and found two suggestions: enabling viewstate and enabling autopostback.

checkBoxName.EnableViewState = true; seems to make no difference, nor did checkBoxName.ViewStateMode = ViewStateMode.Enabled; or any variations on that i tried. checkBoxName.AutoPostBack = true; did SOMETHING, but it's not allowing it to run the code I want. I think that's because it doesn't reach that point because of the next problem:

With AutoPostBack = true, whenever I check or uncheck a box, cbCheckedChangedis not being executed, and the entire page is reloading, resetting back to it's initial state, therefore removing the checkboxes completely from the table.

How can I fix these problems, or at least where might I start looking?




Aucun commentaire:

Enregistrer un commentaire