Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Refreshing Page Content 1

Status
Not open for further replies.

AtomicChip

Programmer
May 15, 2001
622
CA
OK... I have a table that I'm dynamically creating through code based on data from a SQL database. For each record displayed, I create a "delete" button (an ImageButton). The problem that I'm having is that when I click the delete button, the record is deleted from the database, but it still appears on the page. When the page is refreshed, the record disappears. I thought that Response.Flush() may provide some help, but didn't do anything. Has this happened to anyone else, or does anyone have any idea WHY this is happening and how to get around it? -----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
AtomicChip,

It sounds like you aren't rebuilding the table after you delete. It is simply pulling the old table from the ViewState. After you delete the record, you need to call whatever function you are using to create the table text (i.e. if it is a datagrid, call the datagrid binding function, or if it is an html table, call the function that makes the table text).

HTH!
 
bradlkm,

Thanks for the response, but that's exactly what I am doing right now. The table object doesn't actually support ViewState and has to be rebuilt each time the page refreshes. The process that I'm going through right now is:

Build Table - Display
Button Click - Delete From Database
Rebuild Table

It seems like the table is being rendered before the item is deleted. I was thinking that this may be a .net framework issue and was wondering if anyone else has encountered the same difficulty and found any way around it (besides doing a Response.Redirect) -----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
I would have to see some code, I have done this before without trouble so I am guessing it's a simple bug you have overlooked in the code. I'll be glad to see if I can spot it if you wish. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
AtomicChip,

It may be worth stepping through your code to see which is called first, the database query/table building or the delete statement. You may be running the delete code after getting the data from the database. . .

Just a thought. HTH!
 
This is how the code is structured. It has been compiled into a .dll. The content of the table builder code and delete has been removed as I don't believe that that part is important in solving this problem (i might be wrong:p)

void Page_Load ( object sender, EventArgs e )
{
BuildTbls();
}

void BuildTbls ()
{
[SqlConnection Here];
[Table Builder Code Here];
}

void btnDelete_Click ( object sender, EventArgs e )
{
[SqlConnection];
[Delete Record from DB];
}

So every time that the page is refreshed (on first showing too), the table is generated.
-----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Well that would be your problem right there. The Page_load proc is one of the very first to run other than some initialize and new routines.

What you should do is wrap the call to the table builder in pageLoad in a if not ispostback then... end if statment. Then in your delete code call the table builder sub after you do the delete record. That'l do donkey, that'l do
[bravo] Mark
If you are unsure of forum etiquette check here faq796-2540
 
Zarcom,

Thanks for your response. I was under the impression that any called function would be run before the Page_Load was executed. You'd think it would be _logical_ that a click event would run _before_ the page was refreshed, but - guess not. -----------------------------------------------
"The night sky over the planet Krikkit is the least interesting sight in the entire universe."
-Hitch Hiker's Guide To The Galaxy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top