Postback, DataBinding, Refresh

J

John

Hi -

I've got a couple of pages where a DataList is populated only if(!Postback).
I have buttons in the datagrid that allow for the 'deletion' of items from
that DataList.

The problem is that the deleted items don't disappear on Postback, but only
after a page refresh. I assume this is because the DataList is not
redatabound unless !Postback. However, if I remove the if(!Postback)
statement, the button's 'delete' method doesn't seem to work at all.

How can I fix this? Do I need to disable viewstate on some things, or do
something like move my PopulateDataList() method from Page_Load to
Pre_Render? Thus far I've been forcing a page refresh after the 'delete'
method is run, by doing Response.Redirect(Request.RawUrl), and that works,
but it doesn't seem efficient.

Thanks in advance!

-John
 
J

John Saunders

John said:
Hi -

I've got a couple of pages where a DataList is populated only if(!Postback).
I have buttons in the datagrid that allow for the 'deletion' of items from
that DataList.

The problem is that the deleted items don't disappear on Postback, but only
after a page refresh. I assume this is because the DataList is not
redatabound unless !Postback. However, if I remove the if(!Postback)
statement, the button's 'delete' method doesn't seem to work at all.

How can I fix this? Do I need to disable viewstate on some things, or do
something like move my PopulateDataList() method from Page_Load to
Pre_Render? Thus far I've been forcing a page refresh after the 'delete'
method is run, by doing Response.Redirect(Request.RawUrl), and that works,
but it doesn't seem efficient.

John, you'll need to refresh the data in the grid the same way you did in
"if(!PostBack)".
 
J

John

Thanks for the reply!

Just to make sure I understand what you mean - I need to databind again
within the button's 'delete' method after it's made its change to the
database?

Thanks again!

-John
 
J

John Saunders

John said:
Thanks for the reply!

Just to make sure I understand what you mean - I need to databind again
within the button's 'delete' method after it's made its change to the
database?
Yes, that's correct. You might want to do the same thing on inserts or
updates, except that you might be able to short-circuit the process if you
found it worthwhile.

Are you handline paging and sorting yet? Those are another case when a
DataBind is useful.
 
J

John

Excellent - thank you very much for your help.

I haven't had to do much with paging or sorting, yet, but will in the near
future (getting stuck into an assignment where they seem to expect us to
learn everything in one go) - that insight will doubtless save me some
head-scratching. Seemed like it would be a common problem for one who has no
idea what they're doing... I guess I just couldn't get my google-searches
right; so I'm glad I'm sorted now.

Thanks again!

-John
 

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,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top