473,386 Members | 1,775 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,386 software developers and data experts.

Odd viewstate problem with Datagrid template columns

I have a shopping cart datagrid that is filled only the first time the page
is accessed, like so:

If Page.IsPostBack = False Then
RetrieveShoppingCart()
End If

The user can then change the quantity or check a cart item for deletion.
When they click the update button, I am attempting to iterate through the
grid, evaluating the Quantity textbox and Remove checkbox for each cart item
like so:
For Each gridRow As DataGridItem In CartGrid.Items

Dim quantityTextBox As TextBox =
DirectCast(gridRow.FindControl("Quantity"), TextBox)
Dim removeCheckBox As CheckBox =
DirectCast(gridRow.FindControl("Remove"), CheckBox)

If quantityTextBox.Text <> CartGrid.DataKeys(0).ToString() Or
removeCheckBox.Checked Then

The anomoly is that on the first postback, although the two controls are
found, they have not retained their values. The quantityTextBox.Text
property is a blank string, the the removeCheckBox.Checked property is
always the default of False, no matter what it has been set to by the user.

But on each subsequent postback after that, they do retain their changed
values.

The normal reason template controls would lose their value on a postback
would be if the grid was being accidentally rebound at each postback, or
viewstate is not properly set. But neither of these appears to be the case
here. I've literally modified the update button event handler so it does
nothing except display the value of the Quantity textbox on the page using a
label like so:

Dim testTextBox As TextBox =
DirectCast(CartGrid.Items(0).FindControl("Quantity "), TextBox)
TestLabel.Text = "Quantity is : " & testTextBox.Text
Exit Sub

On the first postback the label reads: "Quantity is: "
Each postback thereafter: "Quantity is: 2 (3,4, etc depending
on what its changed to)

Any thoughts on what would cause a first postback to not retain the state of
the controls like this?

Thanks.

---------------------------------------------------------------
Kel Good
MCT, MCAD, MCSD for Microsoft.NET
Nov 19 '05 #1
2 3120
Anyone? Anyone? Buhler?

"Kel Good" <kg***@customsoftware.ca> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
I have a shopping cart datagrid that is filled only the first time the page
is accessed, like so:

If Page.IsPostBack = False Then
RetrieveShoppingCart()
End If

The user can then change the quantity or check a cart item for deletion.
When they click the update button, I am attempting to iterate through the
grid, evaluating the Quantity textbox and Remove checkbox for each cart
item like so:
For Each gridRow As DataGridItem In CartGrid.Items

Dim quantityTextBox As TextBox =
DirectCast(gridRow.FindControl("Quantity"), TextBox)
Dim removeCheckBox As CheckBox =
DirectCast(gridRow.FindControl("Remove"), CheckBox)

If quantityTextBox.Text <> CartGrid.DataKeys(0).ToString() Or
removeCheckBox.Checked Then

The anomoly is that on the first postback, although the two controls are
found, they have not retained their values. The quantityTextBox.Text
property is a blank string, the the removeCheckBox.Checked property is
always the default of False, no matter what it has been set to by the
user.

But on each subsequent postback after that, they do retain their changed
values.

The normal reason template controls would lose their value on a postback
would be if the grid was being accidentally rebound at each postback, or
viewstate is not properly set. But neither of these appears to be the case
here. I've literally modified the update button event handler so it does
nothing except display the value of the Quantity textbox on the page using
a label like so:

Dim testTextBox As TextBox =
DirectCast(CartGrid.Items(0).FindControl("Quantity "), TextBox)
TestLabel.Text = "Quantity is : " & testTextBox.Text
Exit Sub

On the first postback the label reads: "Quantity is: "
Each postback thereafter: "Quantity is: 2 (3,4, etc
depending on what its changed to)

Any thoughts on what would cause a first postback to not retain the state
of the controls like this?

Thanks.

---------------------------------------------------------------
Kel Good
MCT, MCAD, MCSD for Microsoft.NET

Nov 19 '05 #2
can you post a small application that replicates the issue?

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------

"Kel Good" <kg***@customsoftware.ca> wrote in message
news:uA**************@TK2MSFTNGP15.phx.gbl...
Anyone? Anyone? Buhler?

"Kel Good" <kg***@customsoftware.ca> wrote in message
news:Og**************@TK2MSFTNGP09.phx.gbl...
I have a shopping cart datagrid that is filled only the first time the pageis accessed, like so:

If Page.IsPostBack = False Then
RetrieveShoppingCart()
End If

The user can then change the quantity or check a cart item for deletion.
When they click the update button, I am attempting to iterate through the grid, evaluating the Quantity textbox and Remove checkbox for each cart
item like so:
For Each gridRow As DataGridItem In CartGrid.Items

Dim quantityTextBox As TextBox =
DirectCast(gridRow.FindControl("Quantity"), TextBox)
Dim removeCheckBox As CheckBox =
DirectCast(gridRow.FindControl("Remove"), CheckBox)

If quantityTextBox.Text <> CartGrid.DataKeys(0).ToString() Or
removeCheckBox.Checked Then

The anomoly is that on the first postback, although the two controls are
found, they have not retained their values. The quantityTextBox.Text
property is a blank string, the the removeCheckBox.Checked property is
always the default of False, no matter what it has been set to by the
user.

But on each subsequent postback after that, they do retain their changed
values.

The normal reason template controls would lose their value on a postback
would be if the grid was being accidentally rebound at each postback, or
viewstate is not properly set. But neither of these appears to be the case here. I've literally modified the update button event handler so it does
nothing except display the value of the Quantity textbox on the page using a label like so:

Dim testTextBox As TextBox =
DirectCast(CartGrid.Items(0).FindControl("Quantity "), TextBox)
TestLabel.Text = "Quantity is : " & testTextBox.Text
Exit Sub

On the first postback the label reads: "Quantity is: "
Each postback thereafter: "Quantity is: 2 (3,4, etc
depending on what its changed to)

Any thoughts on what would cause a first postback to not retain the state of the controls like this?

Thanks.

---------------------------------------------------------------
Kel Good
MCT, MCAD, MCSD for Microsoft.NET


Nov 19 '05 #3

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

Similar topics

9
by: John Kirksey | last post by:
I have a page that uses an in-place editable DataGrid that supports sorting and paging. EnableViewState is turned ON. At the top of the page are several search fields that allow the user to filter...
2
by: Jay Walker | last post by:
I created a custom DataGridColumn based on Marcie Robillard's MSDN Article: Creating Custom Columns for the ASP.NET Datagrid...
1
by: Sky | last post by:
Although I've been using C# for the last month or so, and accepting out of blind faith the ViewState, I do have some nagging questions about it... can you help verify the following statements? ...
1
by: Paul | last post by:
Hi I have a datagrid with 8 databound columns and a 9th template column with a checkbox control. The data in the datagrid isn't editable only the checkbox. The app is working great, however...
1
by: Amine | last post by:
Hello, I am trying to create textbox control dynamically into a datagrid. I do not know the number of columns until run time so I thought I could use template columns dynamically and add them into...
2
by: Steve Pierce | last post by:
I am having some issues with a runtime dropdownlist in a datagrid. The issue is that I cannot get ViewState to fill the selected index of a runtime dropdown properly on postback. I do not want to...
12
by: TB | last post by:
Hi All: I am trying to create a variation on the standard datagrid, whereby the datagrid is only shown after pressing some buttons. This reason for this is that I would like to use the same...
0
by: Amine | last post by:
Hello, I am trying to create textbox control dynamically into a datagrid. I do not know the number of columns until run time so I thought I could use template columns dynamically and add them into...
2
by: Nomen Nescio | last post by:
Hi, I have a Datagrid with template columns (TextBox and Radiolist in them). When I type something in the textbox and push a radiobutton and subsequently push another button (not part of the...
0
by: stevem2112 | last post by:
I have a datagrid with 2 Template columns. One column has DropDownLists and the other has Textboxes. I bind each DDL in the ItemCreated event. This datagrid is inside a UserControl that is inside...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.