473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamic table and postback

If there is a more appropriate forum, please let me know and I will post
there.

Our field reps can go on to our website and select from several sets of
data to create the address we then provide to their clients in company
correspondence. Using just name as an example, one rep might have a
choice between "James Smith", "James Smith MS, CFP, MBA" and "Jimmy
Smith" while a different rep might have only "Elizabeth Jones" and "Liz
Jones." Similar options exist for address, telephone numbers, etc.,
again with different variations: Smith might have one telephone number
and one fax number, while Jones might have a telephone, cell phone and
two faxes from which to choose.

The current page, written in classic ASP, uses VBScript to open a
database and write out the input controls that are needed. These are
rendered in several tables: one for name, one for address, and so on.
When a rep makes a choice, the form data is submitted to a second ASP
page which records the changes, then returns the user to the page he
just left, adding a note that the changes have been saved.

I am trying to switch this process over to ASP.net 2.0, and it is near
driving me to suicide. My first attempt was to basically cut-n-paste the
existing code into two pages and tidy it all up to work as ASPX, but I
kept getting viewstate errors just loading the code page. I then tried
moving the code to a static module in the app_code folder, but couldn't
figure out how to pass the form values.

So I figured I would rewrite the page from scratch in .NET and
dynamically generate the form fields I needed. The resulting page has a
base table structure, like this:

******
<asp:Table ID="NameTable" runat="server">
<asp:TableRow>
<asp:TableHeaderCell ColumnSpan="3">Name</asp:TableHeaderCell>
</asp:TableRow>
</asp:Table>
******

In the Page.PreRender sub, I pull the existing data out of our database
into a datarow object named Dr, then execute this:

******
i=0
If Dr("Name0").ToString <String.Empty Then
i = ((I + 1) Mod 2)
Tr = New TableRow
Tr.CssClass = String.Format("color{0}", i)

Tc = New TableCell
Tc.Text = "Formal 1:"
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "item"
Rb = New RadioButton
Rb.ID = "RepName0"
Rb.GroupName = "RepName"
If CInt(Dr("NameToClients")) = 0 Then Rb.Checked = True
Tc.Controls.Add(Rb)
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "description"
Tc.Text = Dr("Name0").ToString
Tr.Cells.Add(Tc)
NameTable.Rows.Add(Tr)
End If

If Dr("Name1").ToString <String.Empty Then.... etc.
******

Already on the page is the submit button, coded as

******
<asp:Button ID="SubmitDataButton" runat="server" Text="Submit"
OnClick="SubmitDataButton_Click"></asp:Button>
******

My problem is that on postback (ie when SubmitDataButton is clicked),
the rows I added programmatically no longer exist, which makes it a tad
difficult to retrieve the data. I have run out of ideas and really,
really could use some pointers. What can I do?
--
Gregory Gadow

Sep 8 '06 #1
4 3848
Gregory,

It's a bit difficult to picture what you're trying.

Maybe what you want is a something like this (with a "select" being a link):

+--------------------------------------+
| select | Jon Smith Esq |
| | 17 Any Lane, AnyTown, USA |
|--------+-----------------------------+
| select | Johan Smith, Phd |
| | 99 Business Blvd |
+--------+-----------------------------+

Clicking the select link beside the individual record initiates a post back
where you can do what ever you need to next.

You could do that with a gridview and a form view (or maybe just a literal
that you do the binding for directly).... does that sort look like what you
want?

With more work you could replace the "select" link with a radio button and
then add a "Next" button outside the grid.

Is that the sort of thing you mean?

Regards,

Rob

"Gregory Gadow" <te******@serv.netwrote in message
news:45***************@serv.net...
If there is a more appropriate forum, please let me know and I will post
there.

Our field reps can go on to our website and select from several sets of
data to create the address we then provide to their clients in company
correspondence. Using just name as an example, one rep might have a
choice between "James Smith", "James Smith MS, CFP, MBA" and "Jimmy
Smith" while a different rep might have only "Elizabeth Jones" and "Liz
Jones." Similar options exist for address, telephone numbers, etc.,
again with different variations: Smith might have one telephone number
and one fax number, while Jones might have a telephone, cell phone and
two faxes from which to choose.

The current page, written in classic ASP, uses VBScript to open a
database and write out the input controls that are needed. These are
rendered in several tables: one for name, one for address, and so on.
When a rep makes a choice, the form data is submitted to a second ASP
page which records the changes, then returns the user to the page he
just left, adding a note that the changes have been saved.

I am trying to switch this process over to ASP.net 2.0, and it is near
driving me to suicide. My first attempt was to basically cut-n-paste the
existing code into two pages and tidy it all up to work as ASPX, but I
kept getting viewstate errors just loading the code page. I then tried
moving the code to a static module in the app_code folder, but couldn't
figure out how to pass the form values.

So I figured I would rewrite the page from scratch in .NET and
dynamically generate the form fields I needed. The resulting page has a
base table structure, like this:

******
<asp:Table ID="NameTable" runat="server">
<asp:TableRow>
<asp:TableHeaderCell ColumnSpan="3">Name</asp:TableHeaderCell>
</asp:TableRow>
</asp:Table>
******

In the Page.PreRender sub, I pull the existing data out of our database
into a datarow object named Dr, then execute this:

******
i=0
If Dr("Name0").ToString <String.Empty Then
i = ((I + 1) Mod 2)
Tr = New TableRow
Tr.CssClass = String.Format("color{0}", i)

Tc = New TableCell
Tc.Text = "Formal 1:"
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "item"
Rb = New RadioButton
Rb.ID = "RepName0"
Rb.GroupName = "RepName"
If CInt(Dr("NameToClients")) = 0 Then Rb.Checked = True
Tc.Controls.Add(Rb)
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "description"
Tc.Text = Dr("Name0").ToString
Tr.Cells.Add(Tc)
NameTable.Rows.Add(Tr)
End If

If Dr("Name1").ToString <String.Empty Then.... etc.
******

Already on the page is the submit button, coded as

******
<asp:Button ID="SubmitDataButton" runat="server" Text="Submit"
OnClick="SubmitDataButton_Click"></asp:Button>
******

My problem is that on postback (ie when SubmitDataButton is clicked),
the rows I added programmatically no longer exist, which makes it a tad
difficult to retrieve the data. I have run out of ideas and really,
really could use some pointers. What can I do?
--
Gregory Gadow

Sep 9 '06 #2
Rob MacFadyen wrote:
Gregory,

It's a bit difficult to picture what you're trying.

Maybe what you want is a something like this (with a "select" being a link):

+--------------------------------------+
| select | Jon Smith Esq |
| | 17 Any Lane, AnyTown, USA |
|--------+-----------------------------+
| select | Johan Smith, Phd |
| | 99 Business Blvd |
+--------+-----------------------------+

Clicking the select link beside the individual record initiates a post back
where you can do what ever you need to next.

You could do that with a gridview and a form view (or maybe just a literal
that you do the binding for directly).... does that sort look like what you
want?

With more work you could replace the "select" link with a radio button and
then add a "Next" button outside the grid.

Is that the sort of thing you mean?\
There are five different data items (name, address, telephone, email and web
address), with each item having anywhere between two and six different choices.
Assembling all of the possible combinations and allowing the reps to select one
is probably not the best option.

This shouldn't be difficult to implement, but danged if I can figure it out.

--
Gregory Gadow
te******@serv.net
"Gregory Gadow" <te******@serv.netwrote in message
news:45***************@serv.net...
If there is a more appropriate forum, please let me know and I will post
there.

Our field reps can go on to our website and select from several sets of
data to create the address we then provide to their clients in company
correspondence. Using just name as an example, one rep might have a
choice between "James Smith", "James Smith MS, CFP, MBA" and "Jimmy
Smith" while a different rep might have only "Elizabeth Jones" and "Liz
Jones." Similar options exist for address, telephone numbers, etc.,
again with different variations: Smith might have one telephone number
and one fax number, while Jones might have a telephone, cell phone and
two faxes from which to choose.

The current page, written in classic ASP, uses VBScript to open a
database and write out the input controls that are needed. These are
rendered in several tables: one for name, one for address, and so on.
When a rep makes a choice, the form data is submitted to a second ASP
page which records the changes, then returns the user to the page he
just left, adding a note that the changes have been saved.

I am trying to switch this process over to ASP.net 2.0, and it is near
driving me to suicide. My first attempt was to basically cut-n-paste the
existing code into two pages and tidy it all up to work as ASPX, but I
kept getting viewstate errors just loading the code page. I then tried
moving the code to a static module in the app_code folder, but couldn't
figure out how to pass the form values.

So I figured I would rewrite the page from scratch in .NET and
dynamically generate the form fields I needed. The resulting page has a
base table structure, like this:

******
<asp:Table ID="NameTable" runat="server">
<asp:TableRow>
<asp:TableHeaderCell ColumnSpan="3">Name</asp:TableHeaderCell>
</asp:TableRow>
</asp:Table>
******

In the Page.PreRender sub, I pull the existing data out of our database
into a datarow object named Dr, then execute this:

******
i=0
If Dr("Name0").ToString <String.Empty Then
i = ((I + 1) Mod 2)
Tr = New TableRow
Tr.CssClass = String.Format("color{0}", i)

Tc = New TableCell
Tc.Text = "Formal 1:"
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "item"
Rb = New RadioButton
Rb.ID = "RepName0"
Rb.GroupName = "RepName"
If CInt(Dr("NameToClients")) = 0 Then Rb.Checked = True
Tc.Controls.Add(Rb)
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "description"
Tc.Text = Dr("Name0").ToString
Tr.Cells.Add(Tc)
NameTable.Rows.Add(Tr)
End If

If Dr("Name1").ToString <String.Empty Then.... etc.
******

Already on the page is the submit button, coded as

******
<asp:Button ID="SubmitDataButton" runat="server" Text="Submit"
OnClick="SubmitDataButton_Click"></asp:Button>
******

My problem is that on postback (ie when SubmitDataButton is clicked),
the rows I added programmatically no longer exist, which makes it a tad
difficult to retrieve the data. I have run out of ideas and really,
really could use some pointers. What can I do?
Sep 11 '06 #3
I have found out that there is no solution for what I want to do: Microsoft
has seen fit NOT to preserve the viewstate of a dynamically generated table.
The only way something like this can be done is either to use a static table
with individual elements hidden, or manually maintain the viewstate myself.

--
Gregory Gadow
te******@serv.net
Gregory Gadow wrote:
If there is a more appropriate forum, please let me know and I will post
there.

Our field reps can go on to our website and select from several sets of
data to create the address we then provide to their clients in company
correspondence. Using just name as an example, one rep might have a
choice between "James Smith", "James Smith MS, CFP, MBA" and "Jimmy
Smith" while a different rep might have only "Elizabeth Jones" and "Liz
Jones." Similar options exist for address, telephone numbers, etc.,
again with different variations: Smith might have one telephone number
and one fax number, while Jones might have a telephone, cell phone and
two faxes from which to choose.

The current page, written in classic ASP, uses VBScript to open a
database and write out the input controls that are needed. These are
rendered in several tables: one for name, one for address, and so on.
When a rep makes a choice, the form data is submitted to a second ASP
page which records the changes, then returns the user to the page he
just left, adding a note that the changes have been saved.

I am trying to switch this process over to ASP.net 2.0, and it is near
driving me to suicide. My first attempt was to basically cut-n-paste the
existing code into two pages and tidy it all up to work as ASPX, but I
kept getting viewstate errors just loading the code page. I then tried
moving the code to a static module in the app_code folder, but couldn't
figure out how to pass the form values.

So I figured I would rewrite the page from scratch in .NET and
dynamically generate the form fields I needed. The resulting page has a
base table structure, like this:

******
<asp:Table ID="NameTable" runat="server">
<asp:TableRow>
<asp:TableHeaderCell ColumnSpan="3">Name</asp:TableHeaderCell>
</asp:TableRow>
</asp:Table>
******

In the Page.PreRender sub, I pull the existing data out of our database
into a datarow object named Dr, then execute this:

******
i=0
If Dr("Name0").ToString <String.Empty Then
i = ((I + 1) Mod 2)
Tr = New TableRow
Tr.CssClass = String.Format("color{0}", i)

Tc = New TableCell
Tc.Text = "Formal 1:"
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "item"
Rb = New RadioButton
Rb.ID = "RepName0"
Rb.GroupName = "RepName"
If CInt(Dr("NameToClients")) = 0 Then Rb.Checked = True
Tc.Controls.Add(Rb)
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "description"
Tc.Text = Dr("Name0").ToString
Tr.Cells.Add(Tc)
NameTable.Rows.Add(Tr)
End If

If Dr("Name1").ToString <String.Empty Then.... etc.
******

Already on the page is the submit button, coded as

******
<asp:Button ID="SubmitDataButton" runat="server" Text="Submit"
OnClick="SubmitDataButton_Click"></asp:Button>
******

My problem is that on postback (ie when SubmitDataButton is clicked),
the rows I added programmatically no longer exist, which makes it a tad
difficult to retrieve the data. I have run out of ideas and really,
really could use some pointers. What can I do?
--
Gregory Gadow
Sep 11 '06 #4
Gregory,

The view state is persisted... you're likely running into the classic
"dynamically created controls" problem.

If I understand correctly... by the time Page_Load is called the view state
has been loaded. If you're creating controls, then you need to create them
in the page_init event (that fires before view state is loaded).

Essentially the root of the problem is that when a page goes to load view
state it expects (rightly so) that the page's control tree (page.controls
and descendants) have been created and are ready to load view state. With
dynamically generated controls special care has to be taken to make sure
this is so.

Search of "dynamically creating columns datagrid"... that'll get you close
to a better description (commonly experienced problem for datagrids).

As to your UI problem... I think I understand your problem better... are all
the address elements related? For example if a user chooses Phone Number #2
then there is a corresponding email address they have to choose?

Or is it totally freeform? User could choose phone number #2, email #1, web
address #3?

If the first option... do you have a consistent datasource (eg. select
Name,Email,Phone,WebAddress from UserContactInfo ... one row per choice)? If
so then use a Repeater/DataGrid/GridView and data binding.

Without a consistent datasource (eg. select Name1, Name2, Name3, Email1,
EMail2, Email3 from UserContactInfo ... only one row returned ever) you're
kind of stuck generating the table. Or maybe change the SQL to make the
results one contact info per selected row... will likely require UNION.

If the second option... can you use dropdown lists and data binding. More or
less one dropdown for names, one dropdown for emails, one for web addresses.
The data binding part may well need consitant data source (as above).

Hope that helps,

Rob MacFadyen

"Gregory Gadow" <te******@serv.netwrote in message
news:45**************@serv.net...
>I have found out that there is no solution for what I want to do: Microsoft
has seen fit NOT to preserve the viewstate of a dynamically generated
table.
The only way something like this can be done is either to use a static
table
with individual elements hidden, or manually maintain the viewstate
myself.

--
Gregory Gadow
te******@serv.net
Gregory Gadow wrote:
>If there is a more appropriate forum, please let me know and I will post
there.

Our field reps can go on to our website and select from several sets of
data to create the address we then provide to their clients in company
correspondence. Using just name as an example, one rep might have a
choice between "James Smith", "James Smith MS, CFP, MBA" and "Jimmy
Smith" while a different rep might have only "Elizabeth Jones" and "Liz
Jones." Similar options exist for address, telephone numbers, etc.,
again with different variations: Smith might have one telephone number
and one fax number, while Jones might have a telephone, cell phone and
two faxes from which to choose.

The current page, written in classic ASP, uses VBScript to open a
database and write out the input controls that are needed. These are
rendered in several tables: one for name, one for address, and so on.
When a rep makes a choice, the form data is submitted to a second ASP
page which records the changes, then returns the user to the page he
just left, adding a note that the changes have been saved.

I am trying to switch this process over to ASP.net 2.0, and it is near
driving me to suicide. My first attempt was to basically cut-n-paste the
existing code into two pages and tidy it all up to work as ASPX, but I
kept getting viewstate errors just loading the code page. I then tried
moving the code to a static module in the app_code folder, but couldn't
figure out how to pass the form values.

So I figured I would rewrite the page from scratch in .NET and
dynamically generate the form fields I needed. The resulting page has a
base table structure, like this:

******
<asp:Table ID="NameTable" runat="server">
<asp:TableRow>
<asp:TableHeaderCell ColumnSpan="3">Name</asp:TableHeaderCell>
</asp:TableRow>
</asp:Table>
******

In the Page.PreRender sub, I pull the existing data out of our database
into a datarow object named Dr, then execute this:

******
i=0
If Dr("Name0").ToString <String.Empty Then
i = ((I + 1) Mod 2)
Tr = New TableRow
Tr.CssClass = String.Format("color{0}", i)

Tc = New TableCell
Tc.Text = "Formal 1:"
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "item"
Rb = New RadioButton
Rb.ID = "RepName0"
Rb.GroupName = "RepName"
If CInt(Dr("NameToClients")) = 0 Then Rb.Checked = True
Tc.Controls.Add(Rb)
Tr.Cells.Add(Tc)

Tc = New TableCell
Tc.CssClass = "description"
Tc.Text = Dr("Name0").ToString
Tr.Cells.Add(Tc)
NameTable.Rows.Add(Tr)
End If

If Dr("Name1").ToString <String.Empty Then.... etc.
******

Already on the page is the submit button, coded as

******
<asp:Button ID="SubmitDataButton" runat="server" Text="Submit"
OnClick="SubmitDataButton_Click"></asp:Button>
******

My problem is that on postback (ie when SubmitDataButton is clicked),
the rows I added programmatically no longer exist, which makes it a tad
difficult to retrieve the data. I have run out of ideas and really,
really could use some pointers. What can I do?
--
Gregory Gadow

Sep 12 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: hb | last post by:
Hi, I have a page bill.aspx and its code-behind bill.aspx.cs. On bill.aspx I have: === Select a month: <asp:dropdownlist runat="server" id="lstDate" autopostback="True" /> <br> <asp:table...
1
by: Henke | last post by:
Hello, I have one ImageButton controls which I initialize in Page_Load and declare on class level. ImageButton save = new ImageButton(); save.ImageUrl = "save.gif" save.Click += new...
1
by: Klom Dark | last post by:
I've got a weird problem going on - I've got a table of dynamically created buttons. Each button has the X/Y value of the buttons position in the table assigned to it's CommandArgument property and...
2
by: Dave Williamson | last post by:
When a ASPX page is created with dynamic controls based on what the user is doing the programmer must recreate the dynamic controls again on PostBack in the Page_Load so that it's events are wired...
3
by: Tyler Carver | last post by:
I am trying to use some dynamic controls that are built and then added to tables. The problem that I am having is the timing of when I can populate the controls and have the state remain after a...
5
by: PCH | last post by:
I have an c# asp.net (.net 1.1) web page, viewstate on. The problem I am having is on the button click postback to update. Heres the situation: I have an asp table that has 1 header row. ...
1
by: darrel | last post by:
I have a form that has a 'sub-form' in it that updates a separate table. I can easily add records to this table from within this page. To delete, though, I've been redirecting to a different...
1
by: russ | last post by:
Hi all, Here's a problem I'm having with a dynamic table. Following the guidelines here (http://www.codeproject.com/aspnet/dynamiccontrols.asp), which make perfect sense. The problem is that...
2
by: englishman69 | last post by:
Hello, I have been banging my head against this one for a while... Searches online have revealed many different proposals for correcting my issue but none that I can follow! My basic situation...
3
balabaster
by: balabaster | last post by:
I've got a user control that builds a table of dynamic data based on a :LINQ class holding the data. The data is loaded using the LoadData(DataInstance) method. The table it builds contains a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.