Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Daft question - mind gone blank!

Status
Not open for further replies.

Caradog

Programmer
Jun 28, 2000
73
0
0
GB
Ok, too many beers tonight!

ASP.NET 2.0 / VB.NET

Have one ASPX woth TWO ASCXs (usercontrols of course) on the same page.

Usercontrol A sets a variable.

I then want Usercontrol B to read the value set by A.

Best method besides a session to do this? Expose a public variable???

Ta.
 
another way could be to use ViewState and HttpContext.Items bags...

Known is handfull, Unknown is worldfull
 
This is bad, I know it :) Following on form my post yesterday:

I have created a base class which is inherited by all my usercontrols.

The base class has the following above all the code blocks:

Public Shared intPageID as int32

This variable is then set in control A and read back and displayed *correctly* in control B.

Great, works fine, both controls on the same page set and reads back the right value...

I cannot define a public property on the aspx page containing the two controls for reasons I can't go into here...

...but, as I am aware, the share property sets the variable like an application var, one var for all users of the site. Not good for a multiuser envrionment. Even though every hit to any page in the site will set this value to an ID only specific to that page viewed at that point in time, this is still not the "best practice" way of doing it is it?

If I remove the "share" leaving:

Public intPageID as int32

The var is still accessible across my controls but in control A where the value is set, that's ok, but control B has the value set back to 0 again, now, my lack of formal training is showing up here. How do I expose this variable to all my classes (usercontrols) which once set, is set until the user closes the brower/moves to the next page...

...and no, I don't want to use a session if I can get away with it :)

Ta.
 
>>and no, I don't want to use a session if I can get away with it :)

how about my method???

Known is handfull, Unknown is worldfull
 
Hi vbkris, got any examples of this method or pointers? I had a look at this ealier today but skipped over it...
 
welcome...

Known is handfull, Unknown is worldfull
 
Just in case anyone else is following/searchig this post. In order to share a varaibled between two usercontrols on the same page, I used the following format:

1. Create a base class called "pageProperties" which is inherited by all my usercontrols:

Code:
Public Class pageProperties
    Inherits System.Web.UI.UserControl

    ''' <summary>
    ''' Base Class, all controls inherit this class.
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>

#Region " Public Variables "

    Public Property intPageID() As Int32
        Get
            Return Context.Items("intPageID")
        End Get
        Set(ByVal Value As Int32)
            Context.Items("intPageID") = Value
        End Set
    End Property

#End Region

    Protected Overrides Sub OnLoad(ByVal e As EventArgs)

        MyBase.OnLoad(e)

    End Sub
End Class

2. Next, all usercontrls inherit this class:

Code:
Partial Class toolKit_getStaticContent
    Inherits pageProperties

    ...your code...
End Class
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top