Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

table disappears

Posted on 2006-11-08
14
Medium Priority
?
281 Views
Last Modified: 2008-03-17
Hi,

I fill a Table from my code-behind file (C# ASP.NET 2.0) which is supposed to represent a form.

<asp:Table ID="input_table" runat="server" CellPadding=10 GridLines="Both" BackColor = white>
    </asp:Table>

The table is successfully created here:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            // create table

            … invoke code to create the table

            Session["input_table"] = this.input_table;
}
else
{

}
}

The table is made persistent as shown above. The page also contains a button. In its OnClick method I would like to access the entries of the user (in the table cells). Unfortunatley, the table disappears  when the button is clicked. I am just wondering why this is and how I can prevent it? Any input would be very much appreciated. Many thanks in advance.

Chris
0
Comment
Question by:csetzkorn
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 3
14 Comments
 
LVL 11

Expert Comment

by:ethoths
ID: 17896736
You need to get the table back out of session state in your else clause (if it is a postback).

this.input_table=Session["input_table"]


0
 

Author Comment

by:csetzkorn
ID: 17896753
sorry, I did this but forgot to add it to my post. I seem to be able to access the table in the OnClick method but it disappears.

C
0
 

Author Comment

by:csetzkorn
ID: 17896987
Hi,

It still disappears. Any feedback would be very much appreciate. This is the 'correct code' I am using:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
          // create table

          … invoke code to create the table

          Session["input_table"] = this.input_table;
}
else
{
this.input_table = (Table)Session["input_table"];
}
}
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 11

Expert Comment

by:ethoths
ID: 17897016
You are creating the tabel in the if clause. Are you also adding it to the pages controls collection here. If so you need to do this in the else clause also. Please send your complete code.
0
 

Author Comment

by:csetzkorn
ID: 17897040
The table already exists in the aspx file

<asp:Table ID="input_table" runat="server" CellPadding=10 GridLines="Both" BackColor = white>
</asp:Table>

In Page_Load I add objects (e.g. TextBox[es]) to the table cells. This works fine. The table is shown like a form with all these elements. When I click this button:

<asp:Button id="validate_entries" Runat="server" Font-Bold="True" Text="Validate Entries" OnClick="validateEntriesClick"></asp:Button>
   
I can still access all the objects in the table within the 'validateEntriesClick' method but the table becomes invisible. The question is why this happens? This:

this.input_table = (Table)Session["input_table"];

does not seem enough to make it reappear. Perhaps I do not fully understand the life cycle of the page but I doubt I have to recreate everything ...

Thanks,

C
0
 

Author Comment

by:csetzkorn
ID: 17897245
If I am using:

protected void Page_Load(object sender, EventArgs e)
{
         // create table

          … invoke code to create the table
}

everything works fine (I even don't lose the data entered by the user???). However, this would be too inefficient wouldn't it as the table is created every time ...??!!

C
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17897508
If you are adding the Table dynamically, all dynamic controls need to be recreated on post-back.

Bob
0
 

Author Comment

by:csetzkorn
ID: 17897544
This might be a stupid question. Why can I not put the whole (dyn. created) object (table), which contains all the other objects, and put it in a session object and then (after the postback) do this:

Session["input_table"] = this.input_table;

as I have done before.

Everything works fine if I recreate the table each time after a postback. I am just wondering, why ASP.NET 2.0 is 'clever enough' to restore the values entered by a user (they are still their after a postback).

Thanks.

Christian
0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1000 total points
ID: 17897554
You can store anything serializable into the Session, but that doesn't mean that it is added to the form through that mechanism.  It needs to be rendered in the output HTML.

Bob
0
 

Author Comment

by:csetzkorn
ID: 17897572
ok thanks. that makes sense.

could you possibly answer the second part of my last question?

Thanks.

C
0
 
LVL 96

Expert Comment

by:Bob Learned
ID: 17897583
If you are storing the Table in the Session, on post back are you recreating the Table, or getting it from the Session variable and rendering that?

Bob
0
 

Author Comment

by:csetzkorn
ID: 17897608
no. I am just doing this:

protected void Page_Load(object sender, EventArgs e)
{
         // create table

          … invoke code to create the table
}

and it works as I wanted. It even persists the values entered by users (e.g. after a refresh). I am just wondering why this is? ASP.NET 2.0 seems to do this automatically which is nice.

Thanks,

Christian
0
 
LVL 11

Expert Comment

by:ethoths
ID: 17897625
Yes asp.net does this automatically. It can even raise echanged events as it knows what the previous values was (from viewstate) and it knows what the new values is (from the post collection).

 
0
 

Author Comment

by:csetzkorn
ID: 17897658
Ok thanks for your feedback. I accept Bob's comment (11/08/2006 04:54AM PST
) as it clarifies things.

Chris
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

670 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question