Help me with IsPostBack

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
 
B

bruce barker

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

-- bruce (sqlwork.com)
 
P

Power_mj

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!
 
A

Andy Mortimer [MS]

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
 
A

Alan Pretre

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
 

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

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,078
Latest member
MakersCBDBlood

Latest Threads

Top