Thursday, March 29, 2012

passing values between controls

Hi all, learning the asp.net is a slow process... but I am plodderign
along. I have hit a bit of a snag - I have 4 pages of code here...
control1.ascx
control2.ascx
default.asx... default.asx.vb

relevant details (i think) on default.asx:
<uc1:ProductList ID="ProductList1" runat="server"
OnPreRender="getSelectedProduct" />
<uc2:ProductDetails ID="ProductDetails1" runat="server" /
on default.asx.vb:
Protected Sub getSelectedProduct(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Write("TEST: " & ProductList1.selectedProduct())
End Sub

To this point the system actually works. When i select a product in the
1st User Control, it is displayed on the main page, however, I need to
take this one step further... base what happens in UC2 on what has
happened in UC1.

what would I type in UC2, to reference to get the value of the
selection in UC1 ?You need to think of your user controls as objects...

and as an object, it can expose properties, read and/or write properties.

public string PropertyOfUserControl1
{
get {return "this could be a member variable";}
}

Then you can read the property from uc1, and set a property of uc2.

uc2.PropertyOfUserControl2 = uc1.PropertyOfUserControl1;

If the code behind of uc2...you need to deal with the property you set.

<evandela@.bigpond.net.au> wrote in message
news:1142818077.366768.296410@.g10g2000cwb.googlegr oups.com...
> Hi all, learning the asp.net is a slow process... but I am plodderign
> along. I have hit a bit of a snag - I have 4 pages of code here...
> control1.ascx
> control2.ascx
> default.asx... default.asx.vb
> relevant details (i think) on default.asx:
> <uc1:ProductList ID="ProductList1" runat="server"
> OnPreRender="getSelectedProduct" />
> <uc2:ProductDetails ID="ProductDetails1" runat="server" />
> on default.asx.vb:
> Protected Sub getSelectedProduct(ByVal sender As Object, ByVal e As
> System.EventArgs)
> Response.Write("TEST: " & ProductList1.selectedProduct())
> End Sub
> To this point the system actually works. When i select a product in the
> 1st User Control, it is displayed on the main page, however, I need to
> take this one step further... base what happens in UC2 on what has
> happened in UC1.
> what would I type in UC2, to reference to get the value of the
> selection in UC1 ?

0 comments:

Post a Comment