Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...preserve the controls and the values over postbackspreserve the controls and the values over postbacks
Previous
 
Next
New Post
3/1/2007 4:36 AM
 
I am developing a module i the DNN 4.3.5 and C#. In this module I want to ask the user for the number of rows and columns the user wants for a table. Then when the user clicks a button the postback occurs and in the page_load event I check if it is a postback, if yes, I run "for" loops and create the table using Table t = new Table(); TableRow tr = new TableRow(); TableCell = new TableCell(); Now I have another button (the first dissappears if it is a postback) which when clicked adds appropreate text to the table cells. But when I click the button the table cells do not change as the table and the table rows and the table cells are created again. In short, I loose the data. Is there a way to preserve the table that is dynamically ceated table over postbacks? I want the same table that I create at the first postback to continue. User enters the text for each cell the location number that is, the row no and the column no and clicks a button. This button adds the text to the specified cell. the process repeats till the user is finished. Over the entire process I need to maintain the Table, Table Rows and Cells that I create and edit after each postback.

Please help!!

Regards,

Sasmit.
 
New Post
3/1/2007 9:42 AM
 
Rather than building your table on page load if postback, build the table in the button click event for your first button.  See if that helps you with being able to modify the cells. 

-Mitchel Sellers
Microsoft MVP, ASPInsider, DNN MVP
CEO/Director of Development - IowaComputerGurus Inc.
LinkedIn Profile

Visit mitchelsellers.com for my mostly DNN Blog and support forum.

Visit IowaComputerGurus.com for free DNN Modules, DNN Performance Tips, DNN Consulting Quotes, and DNN Technical Support Services
 
New Post
3/1/2007 11:15 PM
 

What you require is the maintaining of state between postbacks.  Since this state is user specific you have two choices, either store the table information on the server-side via something like session state or push it down to the client in a manner that will be posted back up.  Sometimes people use ViewState for this, sometimes they use their own hidden fields (this is how the ClientAPI manages variables set via setVar/getVar).

If you plan on attempting to try and get ASP.NET to manager your table state via ViewState, you will need to make sure that the table exists before viewstate is loaded in the ASP.NET page lifecycle (before page_load if I remember correctly).

Hope this info proves helpful


 
New Post
3/7/2007 12:27 AM
 
Hi,

Thanks for the info. Can I get some code snippets?? The table would not be exesting when the page first loads. Hence, we can easily handle that in the "IsPostBack" block of the if-coditional in the page_load.

The following is the function I use for creating the table. 'txtRows' and 'txtCols' are two text boxes for getting the number of rows and columns. 'tblDesignArea' is table, 'tr' is table row and 'tc' is table cell.

    // public....
    public TableRow tr;
    public TableCell tc;
    public Table tblDesignArea = new Table();

     protected void createTable()
    {
        if (txtRows.Text != "" && txtCols.Text != "")
        {
            //Add new table rows and columns
            int rows, cols;
            string rowID, cellID;

            for (rows = 1; rows <= Convert.ToInt32(txtRows.Text.ToString()); rows++)
            {
                rowID = "TableRow_" + rows.ToString();
                tr = new TableRow();
                tr.ID = rowID;
                tr.HorizontalAlign = HorizontalAlign.Center;
                tr.VerticalAlign = VerticalAlign.Middle;
                tr.EnableViewState = true;
                tblDesignArea.Rows.Add(tr); //adding row to table...

                for (cols = 1; cols <= Convert.ToInt32(txtCols.Text.ToString()); cols++)
                {
                    cellID = "TableCell_" + rows.ToString() + "_" + cols.ToString();
                    tc = new TableCell();
                    tc.ID = cellID;
                    tc.Height = 25;
                    tc.Width = 125;
                    tc.BorderWidth = 1;
                    tc.BackColor = System.Drawing.Color.White;
                    tc.BorderColor = System.Drawing.Color.LightBlue;
                    tc.ForeColor = System.Drawing.Color.Gray;
                    tc.HorizontalAlign = HorizontalAlign.Center;
                    tc.VerticalAlign = VerticalAlign.Middle;
                    tc.EnableViewState = true;
                   
                    tr.Cells.Add(tc); // adding cell to row.....
                }
            }
        }
        tblDesignArea.EnableViewState = true;
        pnlDesign.Controls.Add(tblDesignArea); // adding table to panel.     
    }  

Let me know how you save the view state and load the view state. I am not sure of what the EnableViewState does....

Neways, do suggest some thing.

Regards,

Sasmit.
 
New Post
3/7/2007 8:38 AM
 

To do what you are trying in the sample above you will need a different control like DataGrid to maintain the tables/rows.  I do not think the table inherintly does this for you.  To get a simple table to do this you will need something like

        if (!Page.IsPostBack)
        {
            Table tbl = new Table();
            TableRow tr = new TableRow();
            TableCell td = new TableCell();
            td.Controls.Add(new LiteralControl("Test"));
            tr.Controls.Add(td);
            tbl.Controls.Add(tr);
            Page.Form.Controls.Add(tbl);
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.IO.StringWriter sw = new System.IO.StringWriter(sb);
            HtmlTextWriter tw = new HtmlTextWriter(sw);
            tbl.RenderControl(tw);
            this.ViewState.Add("mytbl", sb.ToString());
        }
        else
        {
            Page.Form.Controls.Add(new LiteralControl((string) this.ViewState["mytbl"]));
        }

However, if your table contains controls that require event handlers this is not the way to go. 


 
Previous
 
Next
HomeHomeUsing DNN Platf...Using DNN Platf...Administration ...Administration ...preserve the controls and the values over postbackspreserve the controls and the values over postbacks


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out