How to get table control values on post back event?

Hi,

I am using table control in asp.net, there are 3 columns in the table, values of first two columns are added manually at design time and third column has text box where user needs to add values.

On button click event i need to save table (cell) values of column2,column3, but some how on post back event values are disappearing in the table.

There is no limit on rows, it can be one or 20 depends on user selection.

Is there any way to save table values on post back event or can i disable post back event for button so that table values will not be disappeared?

Thanks 

Note: I am not using data set.

 

 

-1
momer123
2/11/2009 6:20:21 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

6 Replies
1022 Views

Similar Articles

[PageSpeed] 22

sounds like you might be executing your code to create the table on postbacks. you only want to run this initiaize code upon first entry to the screen NOT on postbacks.


Rob,
MySpaceCodeZone.net
-1
Rob7500
2/11/2009 7:29:58 PM

momer123:
Is there any way to save table values on post back event
 

You can store the data in ViewState or Session to retain the info on postbacks

momer123:
or can i disable post back event for button so that table values will not be disappeared?
 

OnClientClick of Button set return false;


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
-1
vinz
2/11/2009 7:41:25 PM

Hi vinz,

Thanks for your reply. I can understand that i can save values in session or view state which can be reterived on post back back event but what i like to know is how can i save table rows in session or view state? becuase values are disappearing once i click the button.

If i set on_click event for button control and return false in the function then would table keep the values in all the cells?

-1
momer123
2/11/2009 7:58:05 PM

momer123:
to know is how can i save table rows in session or view state? becuase values are disappearing once i click the button.
 

If you are Adding the controls in the page on every postbacks then you don't have to use ViewState just to retain its values onpostbacks..

Here's an example:

 

    private void GenerateTable()
    {
        Table table = new Table();
        TableCell cell = new TableCell();
        TableRow row = new TableRow();

        int numOfRows = 5;
        for (int i = 0; i < numOfRows; i++)
        {
            TextBox tb = new TextBox();
            tb.ID = "TextBox" + i.ToString();
            cell.Controls.Add(tb);
            row.Cells.Add(cell);
            table.Rows.Add(row);
        }

        Page.Form.Controls.Add(table);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        GenerateTable();
    }

  

I would also suggest you to read on the following articles and FAQ's with regards to Dynamic Controls:


Truly Understanding Dynamic Controls
http://weblogs.asp.net/infinitiesloop/archive/2006/08/25/TRULY-Understanding-Dynamic-Controls-_2800_Part-1_2900_.aspx

Key to ensuring dynamic ASP.NET controls save Viewstate - level 300
http://codebetter.com/blogs/jeffrey.palermo/archive/2004/11/25/33584.aspx

FAQ: Why do dynamic controls disappear on postback and not raise events?
http://forums.asp.net/t/1186195.aspx

 


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
1
vinz
2/11/2009 11:14:46 PM

I am not using dynamic control and i don't want to create table on post back event. i just need table values to store them in the database, at the moment when i click save button all cell values disappear, few cells has text box in it where user enter the values.

any help?

1
momer123
2/12/2009 12:18:06 AM

momer123:
I am not using dynamic control and i don't want to create table on post back event. i just need table values to store them in the database, at the moment when i click save button all cell values disappear, few cells has text box in it where user enter the values.
 

When you say cells do you mean the values on TextBox clears out when you submit?


Regards,Vinz

"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
-1
vinz
2/12/2009 1:08:47 PM
Reply: