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

Saving The quantity of a textbox control between postbacks

I have a shopping cart webpage that shows a product and the Quantity they
would like to order:
When you click the link I want to take the quantity that they entered in the
textbox and post that to the next page. But it keeps the original quantity I
added to the viewstate.
Where can i code this to post the correct quantity.
Here is the code-behind I use.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

If Not IsPostBack Then

' Obtain ProductID from QueryString

Dim ProductID As Integer = CInt(Request.Params("ProductID"))

myProductID = ProductID

' Obtain Product Details

Dim products As IBuySpy.ProductsDB = New IBuySpy.ProductsDB

Dim myProductDetails As IBuySpy.ProductDetails =
products.GetProductDetails(ProductID)

' Update Controls with Product Details

desc.Text = myProductDetails.Description

UnitCost.Text = String.Format("{0:c}", myProductDetails.UnitCost)

'ModelName.Text = myProductDetails.ModelNumber

ModelNumber.Text = myProductDetails.ModelNumber.ToString()

NumericCode.Text = myProductDetails.NumericCode.ToString()

UnitOfMeasure.Text = myProductDetails.UnitofMeasure.ToString()

MinQuantity.Text = myProductDetails.MinQuantity.ToString()

MinQuantity_Hidden.Text = myProductDetails.MinQuantity.ToString()

OrderQuantity.Text = myProductDetails.MinQuantity.ToString()

If myProductDetails.Available = "Y" Then

Available.Text = "Product is Available"

OrderQuantity.Enabled = True

Else

Available.Text = "Product is not available"

OrderQuantity.Enabled = False

End If

ProductImage.ImageUrl = "Images/webimages/" & myProductDetails.ProductImage
& ".gif"

'addToCart.NavigateUrl = "AddToCart.aspx?ProductID=" & ProductID &
"&Referer=" & Me.Request.UrlReferrer.ToString

ReviewList.ProductID = ProductID

AlsoBoughtList.ProductID = ProductID

ViewState("ProductID") = CInt(Request.Params("ProductID"))

ViewState("OrderQuantity") = myProductDetails.MinQuantity.ToString()

ViewState("ReferrerUrl") = Request.UrlReferrer.ToString()

Else

OrderQuantity.Text = ViewState.Item("OrderQuantity")

End If

End Sub

Private Sub AddToCart_Click(ByVal sender As System.Object, ByVal e As
System.Web.UI.ImageClickEventArgs) Handles AddToCart.Click

Response.Redirect("AddToCart.aspx?ProductID=" & ViewState.Item("ProductID")
& "&Quantity=" & ViewState.Item("OrderQuantity") & "&ReturnURL=" &
ViewState("ReferrerUrl"))

End Sub

End Class
Nov 18 '05 #1
2 1603
Hi Gary,
Thanks for posting in the community!
From your description, you used some entry fields to contain productID and
product Quntity info. And there is a linkbutton on the page when the
linkbuton is clicked you 'd like to retrieve the latest values in the
(productID and quantity)entry fields and post them as querystrings to
another page, yes?
If there is anything I misunderstood, please feel free to let me know.

I've viewed the page code you provide and I'd like to ask some further
questions on it:
1. Do use the ViewState to store and retrieve the values of the
textboxes(product quantity),yes? Why don't you directly get the value via
accessing the textbox directly? Such as
Dim quantity as Integer = Integer.parse(txtQuantity.Text ) ?
I think this'll be more direct and simpler, do you think so?

2. You used the below code block in the page's Page_Load event handler:
If Not IsPostBack Then
' Obtain ProductID from QueryString
.........................
...........
Else
OrderQuantity.Text = ViewState.Item("OrderQuantity")
End If

What does this sentense "OrderQuantity.Text =
ViewState.Item("OrderQuantity")" mean? This sentense will make the
"OrderQuantity" textbox's value return to its older value. If you'd like
retrieve the new value, you should directly use the value via
"OrderQuantity.Text" rather than the ViewState because the value in the
ViewState are the former one which is set in the last postback. For more
detailed infos on the ViewState of ASP.NET webpage, you may view the
following
web reference in MSDN:
#Taking a Bite Out of ASP.NET ViewState
http://msdn.microsoft.com/library/en...001.asp?frame=
true

In addition, do you think it possible for you to get the latest value and
post them in the below approach:
Private Sub LinkButton1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles LinkButton1.Click

Dim quantity As Integer = Int32.Parse(txtQuantity.Text)
Response.Redirect("newpage.aspx?quantity=" & quantity.ToString())

End Sub

Thus, the value you get from textbox.Text is the latest value user has
inputed before the page is posted back.

Please check out my suggestion. If you feel anything unclear or if my
suggestion isn't quite suitable for your situation, please feel free to let
me know. I'll be willing to assit you.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Nov 18 '05 #2
Hi Gary,
Have you had a chance to try out my suggestion or have you resolved your
problem? If you need further assistance, please feel free to let me know.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx

Nov 18 '05 #3

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

Similar topics

4
by: RTM | last post by:
Can anyone help me with the following issue? I've seen some similar questions here, but none relating to a textbox control.... I have a form with several controls, one of them being a textbox...
2
by: Lenard Gunda | last post by:
Hi! I have an ASP.NET page with multiple TextBox fields and buttons. When I press the <enter> key in a TextBox, the page postbacks, and one of the buttons get fired (OnClick). Now certain...
1
by: ACaunter | last post by:
Hi all, Could someone please explain to me how i could load a different datagrid or fill out all the textboxes with feilds from a database - once a user types a character in a textbox. I have the...
7
by: joey.powell | last post by:
I have a home page with username and password textboxes and a login button for purposes of users being able to log in (forms authentication) directly on the site home page. I also have a dedicated...
4
by: MattB | last post by:
Hi. I'm working on an intranet application that requires a user to input information about themselves. I have a user control with a couple of textboxes that I want the user to enter their weight...
3
by: Ben Dewey | last post by:
Hey everyone, I have a wierd issue i can't seem to find out whats going on. I have a Control for a Shopping Cart Merchant Page called OrderStatus.ascx Inside that control there is a Repeater...
1
by: jqheller | last post by:
Folks I am losing my mind trying to work with the TemplatedWizardStep. I have created a multistep user registration form that collects plenty of user information including a password. At the end...
6
by: HockeyFan | last post by:
I'd like to have an AJAX textbox that after the user fills in, will auto-fill another textbox on the page without having a postback occur. It doesn't have to do any filtering or any other thing...
3
by: Steve Hershoff | last post by:
Hi everyone, I'm not sure that what I'm trying can't be done (at least, not how I'm trying to do it) but I was hoping for confirmation and possible suggestions on a future approach. We have...
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: 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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...

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.