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. 2 followers. Follow

6 Replies
758 Views

Similar Articles

[PageSpeed] 36

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:

Similar Artilces:

How to maintain form controls value after user control post back?
 hello experts, I have created filter grid in asp.net & C#.My form design has contains 3 dropdown controls and Filter grid(User control).Its working fine(filter), but one problem arise.the form controls are clear when i filter a grid(post back).I tried to reterive values using view state, hidden controls, i got only null values.Anyone please help, its urgent to me. Its my user control code.FilterGrid.aspx<%@ Control Language="C#" AutoEventWireup="true" CodeFile="FilterGrid.ascx.cs" Inherits="FilterGrid" %><style type = "text/css&...

How to get value from dynamic control on Post-back
Hi All, This is my first post. The problem is about dynamic control. 1. In Page Load, I auto generated a datagrid.  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load         Dim lmws As New LIMSWSV10.LIMSService         Dim ds As New DataSet         If Not IsPostBack Then             ds = lmws.GetResultValueForShippingJob(Request.QueryString("ShippingJobID")) ...

Getting control value inside the grid at the post back
Hi,       I used the DropdownList control inside the gridview and i want to retrive the value of dropdown in gridview at the page postback. Is it possible to get the value using "Request.Form"? or is any other method to reteive the value?. Looking for help   Thanks  Dropdownlist ddl = (Dropdownlist)gridview1.rows[gridviewrowno].FindControl("dropdownlistid");string selvalue  = ddl.SelectedValue; in above you have to change  gridviewrowno to the rowno you wants to retrieve.dropdownlistid to the id of the dropdownlist in...

Custom Control post back raises Validation Control's Validate event
Hi all, I have developed a custom pager control, which has been inherited from WebControl, IPostBackDataHandler. Function of the control is to render a pager layout ( page numbers, next, prev, buttons ) and raise an event on the server when page change in UI. Problem is what when i place any validator control which are validate on server only are raising validation on custom pager control's post back. code preview PreRender(){   // Registering client script block that set page index in hidden   // and submit the form} Render(){   // Rend...

Value of Control created dynamically is not getting populated on post back
Hi I am creating a table at run time. If I put some value to textbox, its not getting populated after post back. If I do it on Page onInit event everything works fine.. but I cant do this as I have to make rows on button click. The code is like this Sub MakeTable() Dim ht As New Hashtable ht("1") = "1" ht("2") = "2" For i As Integer = 0 To 2 Dim tr As New TableRow For j As Integer = 0 To 1 Dim td As New TableCell Select Case (j) ...

using javascript getting value from textbox when edit button is clicked and both controls are present in gridview control
Hi All using javascript I want to get value  from textbox when edit button is clicked and both controls that is texbox and button are present in gridview control .Alok Hi aloksinha83, Please see this post: http://forums.asp.net/t/1069245.aspx Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to mark the replies as answers if they help and unmark them if they provide no help....

masterpage and control formatting (table control, HTML table control)
I have a master page that contains 1 contentplaceholder.  In my default.aspx (that uses the masterpage layout) I have a table server control.  During page_load I get the data I need and repeatedly add the usercontrol to the table control, one user control per row.  My user control is basically a HTML table with several rows and columns that's populated with data upon creation. I want this table to fill the contentplaceholder's width. In addition within the masterpage I have a CSS link for my stylesheet. Here are my questions: Is there a better way of adding ...

getting focus back to the same control after post back
Hi friends!  How the control can be set focused on the same conrol after post back from where it was generated?thanks At the event of the control which causes Postback , add {        ControlID.Focus() } in this wayprotected void Page_Load(object sender, EventArgs e) {if (IsPostBack) {Control control = null; string ctrlname = Page.Request.Params["__EVENTTARGET"];if (ctrlname != null && ctrlname != String.Empty) { control = Page.FindControl(ctrlname); control.Focus(); } }   }   Note this will work for all...

Menu control : Cross page posting and posted values in nested controls?
I've created a dyrnamic template for a menu control which renders either a textbox or a linkbutton. The textbox acts as an search input field. The value of this field then acts as input to another page(on another frame actually). What happens is that clicking on the linkbutton will do a postback to Main.aspx(which resides in a frame called 'MainWindow'). When the value arrives at Main.aspx, I see the value from 'searchMovies' textbox posted into the Request.form collection as : 'NavigationMenu$ctl05$searchMovies' with the value that was keyed in. From main.aspx, does anyone know...

getting properties of controls inside a table control
Hi, I h ave a Table control "tbl" in which I am adding other controls such as textboxes and labels dynamically. I am trying to access the propertiesof the controls, such as label1.text and textbox1.text , that I dynamically created and added into the table control. The tbl has two columns, in the first column it has labels and textboxes in the second one Is there anyway I can access the properties of all the controls that I added in different columns and rows of table control by looping through the table. Something like, string temp; for(int i-0;i<=(num...

Control.Value and Control.SelectedItem.Value
Can someone explain to me the difference between say, Dropdownlist.SelectedItem.Value and Dropdownlist.SelectedValue?? Just curious, Thanks!Tim These are going to return the same thing. dropdownlist.selectedvalue is a shortcut to get the currently selected value in the dropdown. If that is all you want then you can just use that. If you want to access the currently selected item you can use dropdownlist.selecteditem and that return the item and you can then access any of the item's properties, including in this case the value property. If this post answered your question please r...

Setting control values in Initialize event will not post the new value.
I am having an issue where I need to set the value of a control on my screen in the InitializeRequest event.  Problem is, when I set it at this point, the value does not post, instead the posted value is the value is was before the Asynchronous Post Back is triggered. Below is a very basic example of the problem.  When the page loads I set the value of the  TextBox1 control = "Auto Script".  Now TextBox1 is set to post back when I click the button on the screen.  In my initialize, I try to set the value of the TextBox1 c...

How to do post back in a dynamically created user control [provided that update panel is in the master page of the page where user control is added] {B/C of FileUpload Control}
I have a register my scriptmanager and place the update panel around contenttempalte for my pages int the master page. Now in one of my pages i am adding some user controls dynamically. In two of my user user controls I have FileUpload control which will not work under partial post back. So I want's full postback for them How could I do that {Provided that i am on the user control,which is inside the page ,and page have the contenttemplat...

Help getting control name and value of dynamic controls
I have an application which creates a dynamic form consisting of an html table with web controls in the page. I need a user to be able to fill in this form and then grab the values of each control and save both the control name and the control value to a database. This is the Code that I have Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If not ispostback then Dim infotable As New Table Dim objparticipant As New Participants.ParticipantInfo Dim objCustomFields As New CustomFieldController Dim TypeId As Intege...

Web resources about - How to get table control values on post back event? - asp.net.presentation-controls

Control - Wikipedia, the free encyclopedia
Text is available under the Creative Commons Attribution-ShareAlike License ;additional terms may apply. By using this site, you agree to the ...

Fitness is ‘escalating beyond control'
HEALTH experts are warning parents that obsessive exercise can be linked to life-threatening eating disorders in teens, amid an explosion of ...

Otway fire still out of control but no threat to Falls Festival
Firefighters are battling to contain an out-of-control Great Otway National Park fire ahead of an expected hot and windy weather spike on Christmas ...

Review: Sugr Cube, the cute wooden portable AirPlay speaker with gesture controls
... rarer, pretty ones even rarer and the Sugr Cube goes one step further in its bid to stand out from the crowd: it offers gesture-based control. ...

North Korea's Red Star OS leaves the government in control of computers
... least not by most people's standards. Like China , the socialist state is keen to embrace the power of the internet, but wants to retain control ...

You can control this family’s Christmas lights over the Internet
... Horrible disaster waiting to happen? You be the judge. You've never met Ken or Rebecca-Ellen and you probably never will. But you can control ...

This is how Amazon is taking control of delivery – and taking it away from UPS
As Amazon searches for ways to speed up delivery, the company this year made big strides toward cutting out the middle man and establishing a ...

The 10 Dumbest Gun Control Political Cartoons of 2015
Perhaps not just 2015. Maybe the dumbest of all times . Say, you mean stricter gun control laws will stop terrorism? No one tell the 300+ victims ...

You can control this family's Christmas lights over the internet and the results are mesmerising
... as they see fit. Visitors are greeted with a live webcam of the Fairbanks, Alaska house — pictured above — as well as a bank of controls for ...

Afghan officials: Key district besieged by Taliban still under state control
"Taliban rumors that they have captured the district are not true," says local official trapped for 3 days before government reinforcements arrived ...

Resources last updated: 12/28/2015 12:02:31 AM