Help me with IsPostBack

  • Thread starter Thread starter Alan Pretre
  • Start date Start date
A

Alan Pretre

I have a a WebForms.Table control that I am populating in Page_Load(). One
of the columns has cells with a button in each row, which I wire up to its
Click event handler. Everything is fine if I don't condition the table fill
on IsPostBack. But if I use IsPostBack, like so:

Page_Load()
{
if (!IsPostBack)
{
fill the table, including creating the buttons
}

// Then wire up the buttons
foreach (row in the table)
{
attach the click event handler
}
}

then the table is empty.

The table fill is costly and I'd only like to fill it once. Can you help me
with this. I do have EnableViewState=true on the table control.

-- Alan
 
you have to refill the table on postback if you want to get events, or look
at postback values.

-- bruce (sqlwork.com)
 
You can write a function named ShowTable(). and then you
should invole it in page_load without if(!IsPostBack).
private void ShowTable(){
// here build a table and its event
}

public void Page_Load(){
this.ShowTable();
if(!IsPostBack){
// your other logic code
}
}

and you can invole showtable function in InitCommponent()
function of current page.I think so!
 
If your table fill is costly, is the data quite consistent, i.e. does it
change much? If not, you might want to consider creating a user control to
house the table. Then have an OutputCache setting on that user control see
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/htm
l/cpconcachingportionsofaspnetpage.asp
http://support.microsoft.com/default.aspx?kbid=308375

Alternatively, if it is the aquisition of the data for the table which is
costly, store the data somehow rather than hitting a database each time.
For e.g. in ViewState or Session state?

Regards

Andy Mortimer [MS]
Please do not send email directly to this alias. This alias is for
newsgroup purposes only
 
bruce barker said:
you have to refill the table on postback if you want to get events, or look
at postback values.

Bruce, do you have a link where I can learn more about this aspect of
IsPostBack?

-- Alan
 
Back
Top