Last post Jun 22, 2005 01:28 AM by ikamiksok
May 06, 2005 05:01 PM|notoriousvic|LINK
I have a repeater on my aspx page and within the repeater I have a checkbox
<code><input enableviewstate="false" type="checkbox" id="itemConfirmed" runat="server" onClick="document.getElementById('conID').value=this.value; this.form.submit();" ></code>
I also set a Data Bound event on the repeater.
With in the onItemDataBound sub I make sure the checkbox is unchecked.
Public Sub setTravel(sender
as Object, e
As System.Web.UI.WebControls.RepeaterItem =
'repeater item must be template or alternating template
The problem that I am having is that no matter what I set the checkbox to, the checkbox ends up having the same value as a previously viewed page. So for example if I view a page with all checkboxes checked off. The next page
(it posts to the next page) will have the same checkboxes checked off. I included enableviewstate="false" but it doesn't matter. The checkbox gets automatically filled with previous page.
Is there anyway to override this functionality?
Any help would be appreciated, Thanks
May 07, 2005 12:10 PM|Bug_Bugger|LINK
Are you saying that if page is posted back then checkboxes will retain their checked status? As i understand, you do not databind again when that postback happens, right?
Most likely the problem is related to the fact that checkbox is not only server but also a client control and when posted back, Request will always contain the data related to the checked checkboxes regardless of the value of EnableViewState property (for
a comparison, take a label control - it is only a server side control which is rendered as <span therefore its value never is posted back and the only way to persist label's value between requests is to use the viewstate)
Bottomline - dirtly fix would be re-binding the repeater on every postback before the page is rendered. Alternatively, create a function that will loop through the Items collection of the Repeater and uncheck the checkboxes (instead of doing so in the ItemDataBound
event). Then simply call this function before the page is rendered.
Hope this helps
May 07, 2005 06:08 PM|notoriousvic|LINK
Yes check boxes retain their status if I do a postback even if I specify enableviewstate as false.
I re-databind the repeater on each post back but I do not bind any value to the checkbox but the checkbox (runat="server") retains it's previous value anyhow.
I have found a work around.
Within the onItemDataBound procedure I reassign the id of the checkbox to a unique database value.
CType(currentItem.FindControl("itemConfirmed"),System.Web.UI.HtmlControls.HtmlInputCheckBox).id = currentItem.DataItem.item("id")
I just find it strange that asp.net will retain same values for repeater items on postback even if you speficy enableviewstate as false. I wish I knew what was going on.
Thanks for your help
Jun 22, 2005 01:28 AM|ikamiksok|LINK