Persisting a table web control

J

John Smith Jr.

I am looking for some way to persist a table web control so when page_load
event comes up, i can display the table as it was. I tried using ViewState
with the rows collection but that didn't work to well as I got an error
trying to put rows collection in the viewstate.

My problem is this:

I load a table with rows and controls, then wire events, this is after
clearing the rows of the table initially in this function.

When clicking a particular button, I want it to reload the page based on
data in this button, problem is, every page load I clear the table and
repopulate it. So the particular button is wiped and a new one created, I
think this is what is causing things to act funky. Is storing the rows
collection as a rows collection (in session. viewstate. or class variable)
my best option? Is there another way? i tried using datagrid and
databinding, but I had problems figuring out how to place controls in rows
with datagrid, and the table works great up to this point. So I wanted to
get past this hurddle and maybe re-write it into a better contol later.
 
R

Rocky Moore

John Smith Jr. said:
I am looking for some way to persist a table web control so when page_load
event comes up, i can display the table as it was. I tried using ViewState
with the rows collection but that didn't work to well as I got an error
trying to put rows collection in the viewstate.

My problem is this:

I load a table with rows and controls, then wire events, this is after
clearing the rows of the table initially in this function.

When clicking a particular button, I want it to reload the page based on
data in this button, problem is, every page load I clear the table and
repopulate it. So the particular button is wiped and a new one created, I
think this is what is causing things to act funky. Is storing the rows
collection as a rows collection (in session. viewstate. or class variable)
my best option? Is there another way? i tried using datagrid and
databinding, but I had problems figuring out how to place controls in rows
with datagrid, and the table works great up to this point. So I wanted to
get past this hurddle and maybe re-write it into a better contol later.

I am not sure I am getting this correctly, but do you use the !IsPostBack in
your Page_Load? If it is an Web control and ViewState is in use for that
control, it should keep track of its data all by itself as long as you do
not recreate it on postbacks.

Rocky Moore
www.HintsAndTips.com
 
J

John Smith Jr.

Well the first problem is the table contains dynamic controls and events in
each row.

But i have tried only populate on page_load that isn't a post back and the
table is always empty for me.

I tried putting my populate table code in the !Page.IsPostBack and the table
is blank on PostBack.
 
R

Rocky Moore

John Smith Jr. said:
Well the first problem is the table contains dynamic controls and events in
each row.

But i have tried only populate on page_load that isn't a post back and the
table is always empty for me.

I tried putting my populate table code in the !Page.IsPostBack and the table
is blank on PostBack.

You say you want it to display the table based on the "data in the button".
What data would this be? Can you store that data in your viewstate and
simply post back an ID to that date so that your routine generates the
proper table? Is there an example?

Rocky Moore
www.HintsAndTips.com
 
J

John Smith Jr.

Page Load
UpdateTable()

UpdateTable()
Get List of Data
Clear Table
Populate Table with Data
Populate Table (last cell) with control buttons
Wire events for buttons

Event
Button.Attribute[""]
UpdateTable() with new data (ie drill down the data in table)

As you can see, Page_Load calls clear table to repopulate it.
Now this is removing the old controls/events, so events arn't firing
properly.

Since I am using dynamic controls/events, I some how need to keep the same
controls/event wired up, I believe what is happening now is when Page_load
is called, it clears the table, creates new rows and buttons/events, since
these events arnt' the same as the last pass, when the button click event
would normally fire (after page-load) it doesn't cause it no longer exists
(at least the instance that was called, the button still exists as it was
recreated, but it is a "new" button).

So I was looking to save the old table out with the contols so on page load
I can simple reload them, and on button click, I can do the update.

I am fairly new to ASP.NET, so I might be missing something, but I beeen
struggling with this for a while now.

The code can be viewed at www.vampired.net/code.txt this is an old copy,
but shows the same problem.
 
R

Rocky Moore

John Smith Jr. said:
Page Load
UpdateTable()

UpdateTable()
Get List of Data
Clear Table
Populate Table with Data
Populate Table (last cell) with control buttons
Wire events for buttons

Event
Button.Attribute[""]
UpdateTable() with new data (ie drill down the data in table)

As you can see, Page_Load calls clear table to repopulate it.
Now this is removing the old controls/events, so events arn't firing
properly.

Since I am using dynamic controls/events, I some how need to keep the same
controls/event wired up, I believe what is happening now is when Page_load
is called, it clears the table, creates new rows and buttons/events, since
these events arnt' the same as the last pass, when the button click event
would normally fire (after page-load) it doesn't cause it no longer exists
(at least the instance that was called, the button still exists as it was
recreated, but it is a "new" button).

So I was looking to save the old table out with the contols so on page load
I can simple reload them, and on button click, I can do the update.

I am fairly new to ASP.NET, so I might be missing something, but I beeen
struggling with this for a while now.

The code can be viewed at www.vampired.net/code.txt this is an old copy,
but shows the same problem.

This may not be quite what you want to hear, but the code works fine for me
..NET V1.0 ;)

There must be something higher than this which is the problem. Does the
document have SessionsState and ViewState enabled?

Do you know "where" it is losing the click event? That is, does it post
back, go through the creation of the table and buttons with the proper
directory (last one used to build the table)?

You might throw in more traces to make sure it is building the tables and
buttons the same and that the name IDs.

Rocky Moore
www.HintsAndTips.com
 
E

Eric Veltman

Hello,
Since I am using dynamic controls/events, I some how need to keep the same
controls/event wired up, I believe what is happening now is when Page_load
is called, it clears the table, creates new rows and buttons/events, since
these events arnt' the same as the last pass, when the button click event
would normally fire (after page-load) it doesn't cause it no longer exists
(at least the instance that was called, the button still exists as it was
recreated, but it is a "new" button).

You can re-create the dynamically created controls during Page_Load
and handle the events, but you have to ensure that the IDs of the
dynamically created controls stay the same !

Assign the IDs yourself instead of using automatic ID assignment.
With automatic assignment, the ID of the button in the same row
will differ when you create it in Page_Load and Button_Click.
As a result, ASP.NET can't pass the post data to the right button control.

Best regards,

Eric
 
J

John Smith Jr.

The very first click works, but after that it requires two clicks

Rocky Moore said:
John Smith Jr. said:
Page Load
UpdateTable()

UpdateTable()
Get List of Data
Clear Table
Populate Table with Data
Populate Table (last cell) with control buttons
Wire events for buttons

Event
Button.Attribute[""]
UpdateTable() with new data (ie drill down the data in table)

As you can see, Page_Load calls clear table to repopulate it.
Now this is removing the old controls/events, so events arn't firing
properly.

Since I am using dynamic controls/events, I some how need to keep the same
controls/event wired up, I believe what is happening now is when Page_load
is called, it clears the table, creates new rows and buttons/events, since
these events arnt' the same as the last pass, when the button click event
would normally fire (after page-load) it doesn't cause it no longer exists
(at least the instance that was called, the button still exists as it was
recreated, but it is a "new" button).

So I was looking to save the old table out with the contols so on page load
I can simple reload them, and on button click, I can do the update.

I am fairly new to ASP.NET, so I might be missing something, but I beeen
struggling with this for a while now.

The code can be viewed at www.vampired.net/code.txt this is an old copy,
but shows the same problem.

This may not be quite what you want to hear, but the code works fine for me
.NET V1.0 ;)

There must be something higher than this which is the problem. Does the
document have SessionsState and ViewState enabled?

Do you know "where" it is losing the click event? That is, does it post
back, go through the creation of the table and buttons with the proper
directory (last one used to build the table)?

You might throw in more traces to make sure it is building the tables and
buttons the same and that the name IDs.

Rocky Moore
www.HintsAndTips.com

and
the table
and
the
controls
in
 
J

John Smith Jr.

That did it!!

Thanks!

Eric Veltman said:
Hello,


You can re-create the dynamically created controls during Page_Load
and handle the events, but you have to ensure that the IDs of the
dynamically created controls stay the same !

Assign the IDs yourself instead of using automatic ID assignment.
With automatic assignment, the ID of the button in the same row
will differ when you create it in Page_Load and Button_Click.
As a result, ASP.NET can't pass the post data to the right button control.

Best regards,

Eric
 

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,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top