Monday, March 26, 2012

web controls sharing information

I have a web form that contains two user controls (.ascx files). One of those controls contains order information like shipping cost, tax and order total. The other control contains additional information and submits the page through a sub procedure that writes information to a database. How do I access the shipping cost, tax and order total from the first control to be submitted with the second control?

Hey,

In the code-behind page, expose them as properties. Create properties that expose the values of the textboxes/dropdownlists for the controls that hold the shipping cost, tax, etc.


Thanks. Not sure I'm doing this right. I've created a new class as below in a .vb file separate from both ascx files:

PublicClass OrderDetails

PublicSubNew()

EndSub

Private _SubTotalAsDecimal

PublicProperty SubTotalAmt()AsDecimal

Get

Return _SubTotal

EndGet

Set(ByVal ValueAsDecimal)

_SubTotal = Value

EndSet

EndProperty

EndClass


Then on the first acsx file I've created an instance of the object like this:

Dim MyOrderDetailsAsNew OrderDetails

MyOrderDetails.SubTotalAmt = cart.GetSubtotalAmount()

subtotalLabel.Text =String.Format("{0:c}", MyOrderDetails.SubTotalAmt)


So far so good, but then I want to access the value that is now stored in MyOrderDetails.SubTotalAmt from the second acsx file like this:

Dim orderSubTotal = OrderDetails.MyOrderDetails.SubTotalAmt

And I get the following error:
MyOrderDetails' is not a member of 'appname.OrderDetails'.

I know I'm missing something here as I am new to ASP.NET and VB.NET. Thanks for your help.


Try changing this:
Dim MyOrderDetailsAsNew OrderDetails
To:
Public MyOrderDetailsAsNew OrderDetails

NC...

0 comments:

Post a Comment