What happens between events Load and PreRender. ASP.NET bug?

M

mortb

Just post the code where the checked state of the checkbox is set
(databinding?)
(probably in page load)

cheers,
mortb
 
F

Francois

Hi,

First of all sorry for the long post but I believe it is quite an
interesting as well as advanced and complex problem.

I have a problem with the checkbox control I have in my repeater.
I am using a repeater that I bind to some data in the Page_Load method.
That page is heavy and highly dynamic and the viewstate of the repeater and
all the controls existing in that repeater are set to "False" as none of the
information in the repeater needs to be posted back to the server. It is
rather an other control in that page that makes the postback happen and
repopulate the repeater upon those values. Those controls actually filter
date in and out. The repeater can be seen as a read only view of data.

To visualize the problem let have a simplified view of the repeater and for
later purpose, I will also put in brackets the UniqueID of each checkbox
control in my repeater. My repeater got 3 rows, each row got a checkbox.

row number -- checkbox
1 true
(Repeater:_ctl1:CheckBoxSuspended)
2 false
(Repeater:_ctl2:CheckBoxSuspended)
3 false
(Repeater:_ctl3:CheckBoxSuspended)

When i select some options in my page that makes the page postback, the
Page_Load run, and due to the option i chose, only the row number 3 will be
selected from my dataset and then only that row will be binded to my
repeater.
In the Repeater_ItemDataBound event handler, I read the checkbox value from
the database (which is false) and assign in to the checkbox. So far, so
good. But the HTML rendered displays the checkbox being true.

To visualize the problem, My repeater displays:

rowNumber -- checkbox
3 true
(Repeater:_ctl1:CheckBoxSuspended)

instead of:

rowNumber -- checkbox
3 false
(Repeater:_ctl1:CheckBoxSuspended)

Wondering why, I overloaded a few event handlers in my page and I see that
AFTER Page.OnLoad() method is called and BEFORE Page.OnPreRender() is
called, the checkbox value is changed from false (the value i manually set
when i databind the repeater) to true, thus making the CheckedChanged event
to fire.
My only clue is that in between Page.OnLoad() and Page.OnPreRender() , the
ASP.NET runtime retrieves what ASP.NET think is the past value of the
checkbox (as it takes the old value of the control with the uniqueID
Repeater:_ctl1:CheckBoxSuspended and put it in the new control with that
same UniqueID). The problem is that even those controls have the same
UniqueID, they correspond to different data in the DB and then, must keep
their value I set at databinding time.
Then I wonder if there is a bug in the ASP.NET lifecyle or if it is me who
is not aware of some features. But i think it is very strange that ASP.NET
decide by "itself" to set the value of my checkbox control AFTER I set it by
myself in the binding of my repeater. This is in my opinion something that
should never happen.
Also where does ASP.NET can possibly know what was the previous value of
Repeater:_ctl1:CheckBoxSuspended as i set EnableViewState="False" in the
aspx code? Is it from some cache? or is the viewstate saved anyway?

Any guru in here who can give me an help and explain me how to solve this?
If needed i could send over all my source code but as it is part of an
application that would mean a lot of code!

Best regards and thanks to have read this until the end !

Francois
 
F

Francois

in the databinding, the binding code is:

CheckBoxValue checkBoxSuspended = (CheckBoxValue)
repeaterItem.FindControl("CheckBoxSuspended");
checkBoxSuspended.Checked = (bool) record["isSuspended"];
checkBoxSuspended.Attributes.Add("onclick", "changeSuspendGame(" +
checkBoxSuspended.ClientID + ", " + gameId + ")");

But this code works well as when i run it in debug mode everything is fine,
as i said in the original post it is later that some internal code of the
asp.net runtime changes the values by itself.

Francois
 
B

bruce barker

after a control is created, the ipostbackdatahandler is called if any
postback data is found for it. control which will receive postback data
must be created by prerender.

if you data is readonly, rather than use a checkboxs and textboxes, which
have to postback, use images and literals. you could also create a new
checkbox control which ignored the postback data.


-- bruce (sqlwork.com)





| Hi,
|
| First of all sorry for the long post but I believe it is quite an
| interesting as well as advanced and complex problem.
|
| I have a problem with the checkbox control I have in my repeater.
| I am using a repeater that I bind to some data in the Page_Load method.
| That page is heavy and highly dynamic and the viewstate of the repeater
and
| all the controls existing in that repeater are set to "False" as none of
the
| information in the repeater needs to be posted back to the server. It is
| rather an other control in that page that makes the postback happen and
| repopulate the repeater upon those values. Those controls actually filter
| date in and out. The repeater can be seen as a read only view of data.
|
| To visualize the problem let have a simplified view of the repeater and
for
| later purpose, I will also put in brackets the UniqueID of each checkbox
| control in my repeater. My repeater got 3 rows, each row got a checkbox.
|
| row number -- checkbox
| 1 true
| (Repeater:_ctl1:CheckBoxSuspended)
| 2 false
| (Repeater:_ctl2:CheckBoxSuspended)
| 3 false
| (Repeater:_ctl3:CheckBoxSuspended)
|
| When i select some options in my page that makes the page postback, the
| Page_Load run, and due to the option i chose, only the row number 3 will
be
| selected from my dataset and then only that row will be binded to my
| repeater.
| In the Repeater_ItemDataBound event handler, I read the checkbox value
from
| the database (which is false) and assign in to the checkbox. So far, so
| good. But the HTML rendered displays the checkbox being true.
|
| To visualize the problem, My repeater displays:
|
| rowNumber -- checkbox
| 3 true
| (Repeater:_ctl1:CheckBoxSuspended)
|
| instead of:
|
| rowNumber -- checkbox
| 3 false
| (Repeater:_ctl1:CheckBoxSuspended)
|
| Wondering why, I overloaded a few event handlers in my page and I see that
| AFTER Page.OnLoad() method is called and BEFORE Page.OnPreRender() is
| called, the checkbox value is changed from false (the value i manually set
| when i databind the repeater) to true, thus making the CheckedChanged
event
| to fire.
| My only clue is that in between Page.OnLoad() and Page.OnPreRender() , the
| ASP.NET runtime retrieves what ASP.NET think is the past value of the
| checkbox (as it takes the old value of the control with the uniqueID
| Repeater:_ctl1:CheckBoxSuspended and put it in the new control with that
| same UniqueID). The problem is that even those controls have the same
| UniqueID, they correspond to different data in the DB and then, must keep
| their value I set at databinding time.
| Then I wonder if there is a bug in the ASP.NET lifecyle or if it is me who
| is not aware of some features. But i think it is very strange that ASP.NET
| decide by "itself" to set the value of my checkbox control AFTER I set it
by
| myself in the binding of my repeater. This is in my opinion something that
| should never happen.
| Also where does ASP.NET can possibly know what was the previous value of
| Repeater:_ctl1:CheckBoxSuspended as i set EnableViewState="False" in the
| aspx code? Is it from some cache? or is the viewstate saved anyway?
|
| Any guru in here who can give me an help and explain me how to solve this?
| If needed i could send over all my source code but as it is part of an
| application that would mean a lot of code!
|
| Best regards and thanks to have read this until the end !
|
| Francois
|
|
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top