Last post Jul 25, 2011 10:23 AM by superguppie
Jul 05, 2011 04:27 PM|islam007_84|LINK
i have a listview control in a form with an imagebutton inside it.
i put some code in the ListView ItemDataBound event so i can modify the path of the image for the (image button) according to some data in the listview and some other data which is stored in a variable (this variable is set in the page load event)
this worked fine in the first page requesting.
but when i call the page again by clicking some other button somewhere (postback) i noticed that the listview ItemDataBound event fires before the page load event.
so it gives me error because the variabe it needs is empty (because it is set in the load ) .
i tried to use the listview itemcreated event and this is even worse because this event fires many times and still has the same problem.
i don't want to set the variable in the begining of the ListView ItemDataBound event because the information that goes into this variable comes from a function that takes a littile long time.
any idea how to prevent the listview ItemDataBound event from firing before the page load event.?
Jul 05, 2011 06:35 PM|manishgvsharma2000|LINK
you need to handle you code like below
On form load event where below code
if IsPostback=false then // this when form load first time that is false , after post back it is true automatic
do ur work///
Jul 05, 2011 07:45 PM|islam007_84|LINK
but that doesn't solve my problem ....
whether i set the variable inside the if block or outside ... still the itemdatabound event fires first!!!
by the way i use a sql datasource that binds automatically with the list view.
any other suggestions??
Jul 05, 2011 07:50 PM|luappy13|LINK
events do fire first
Jul 06, 2011 10:55 AM|islam007_84|LINK
events do fire first
if you trace the page events well you should see that with each postback the page_load fires first (even if another control event causes this postback)
Jul 06, 2011 03:01 PM|islam007_84|LINK
in fact i found out that the sqldatasource that is boud to the listview is firing its selecting (thats why).
i serached the net and my real problem is like this :
please help me!!!
Jul 07, 2011 08:19 AM|Qin Dian Tang - MSFT|LINK
You can save the data into a Session instead of a variable. You can check the page life cycle to understand what the issue is.
Jul 25, 2011 10:23 AM|superguppie|LINK
Sorry for the late response. Since noone mentioned it:
I think you have EnableViewState="false" on the ListView. This will cause ASP.NET to do a DataBind when it gets a PostBack to rebuild the ListView. The rebuilt ListView is needed to process the posted data.
Set EnableViewState="true" (which is the default) to stop the DataBind on PostBack. However, you may not want to, since there must have been a reason for turning off ViewState for the ListView.