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

Problem declaring "Public Property" and "Friend Shared"

Hello,

I have a problem declaring variables. I need to create an object oRpte
as ReportClass on WebForm1.aspx and be able to use its value on
WebForm2.aspx.
For declaring the property oRpte() on WebForm1.aspx, I use "Public
Property" and I declare variable _oRpte as Friend Shared. That's my
problem. If I don't declare _oRpte as Friend Shared, I can't use
WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend
Shared, I can use WebForm1.oRpte() with its old value, but if there
are two users navigating WebPage2.aspx at the same time, then
WebForm1.oRpte() can get different values, I can't keep the same value
of WebForm1.oRpte() for both users.
How should I declare the variables, please?

Public Class WebForm1.aspx
Inherits System.Web.UI.Page
Friend Shared _oRpte As ReportClass
......
' more code
......
Private Sub MyFunction()
Dim oRpt As New MyCrystalReport
oRpt.SetDataSource(MydataTable)
Me.oRpte = oRpt
End Sub

Public Property oRpte() As ReportClass
Get
Return _oRpte
End Get
Set(ByVal strValor1 As ReportClass)
_oRpte = strValor1
End Set
End Property
End Class

On WebForm2.aspx, I try to use object oRpte of WebForm1.aspx, but no
success:

Dim oRptx As New ReportClass
Dim wform As New WebForm1
oRptx = wform.oRpte
' I get error here:
oRptx.SetParameterValue("param1", strMessageOnRapport)
'I can't call oRptx

Should I declare like:
Protected Shared _oRpte As ReportClass
instead of
Friend Shared _oRpte As ReportClass
??

Aug 8 '06 #1
3 2237
jb*****@gmail.com wrote:
Hello,

I have a problem declaring variables. I need to create an object oRpte
as ReportClass on WebForm1.aspx and be able to use its value on
WebForm2.aspx.
For declaring the property oRpte() on WebForm1.aspx, I use "Public
Property" and I declare variable _oRpte as Friend Shared. That's my
problem. If I don't declare _oRpte as Friend Shared, I can't use
WebForm1.oRpte() on other webpage. If I declare _oRpte as Friend
Shared, I can use WebForm1.oRpte() with its old value, but if there
are two users navigating WebPage2.aspx at the same time, then
WebForm1.oRpte() can get different values, I can't keep the same value
of WebForm1.oRpte() for both users.
How should I declare the variables, please?
WebForms don't maintain per-user state. If you need to maintain
per-user state, use Session variables. If you're using InProc session,
you'll need to make very few changes to your code [just replace
assignments to _oRpte with Session("oRpte") =, and references to _oRpte
with CType(Session("oRpte"),ReportClass)]. If you're using StateServer
or SQL Server state, you'll probably have more issues, since in this
case, ReportClass would have to be serializable.

If it isn't feasible for ReportClass to be serializable, you may have
to go for a more hackish approach (e.g. having a global hashtable using
the users session id to find a reference to the ReportClass - this may
scale poorly, and become unmanageable, and you'll need to have some way
of discarding "old" session information)

Damien

Aug 8 '06 #2
I was using Session("oRpte") for a long time, but I think that it
consumes more memory and down performance (I think Crystal Report in a
Session is too much).

Even if I declare Protected Friend o_Rpte as ReportClass, would I have
the same problem?

Anyway, thank you very much, Damien.

Aug 8 '06 #3
Big George wrote:
I was using Session("oRpte") for a long time, but I think that it
consumes more memory and down performance (I think Crystal Report in a
Session is too much).

Even if I declare Protected Friend o_Rpte as ReportClass, would I have
the same problem?

Anyway, thank you very much, Damien.
Hi George,

You're trying to maintain state between two separate requests to the
server. That's exactly the problem that Session was built as the
solution to. You're question about having a property that's visible to
one page from another suggests to me that you've not quite "got" the
ASP.NET page model yet (apologies if that sounds offensive, or if you
do understand the ASP.Net page model quite well):

In ASP.Net, each request comes in, an instance of the page which is
being requested is created, the page processes the request, and then
the instance goes out of scope (to be Garbage collected at some point
in the future). So when the second request comes in (to WebForm2),
there's no way to get hold of a reference to the *instance* of WebForm1
which processed the previous request for the same user. It may have
been GCed already. As you've already discovered, the only way for
WebForm1 to have a property which you can reference from WebForm2 is
for the property to be Shared. But in this case, there's only one copy
of the property for the entire application, which as you've spotted,
makes it a single user system.

I think you come down to having two (and two half) choices:
1) Store the report in the session.
2) Keep the information in the session to recreate the report
[3]) Store all of the reports in a hashtable, keyed by the session ID.
[4]) Store a reference to WebForm1 in the session.

1 and [3] will keep the entire report in memory (as would your
approach, based on what you were trying to do), so will still have the
memory and performance issues you observed previously.

2 will reduce your memory overhead, but will have a greater performance
effect (probably).

[4] will let you use the property that you've been trying to add. But
it's just going to be even more wasteful of memory that 1, and a small
additional processing overhead.

So you need to decide whether you're optimizing for memory or
performance, and pick the winner from there. ([3] is a poor version of
1, but works for out of process session state. But you need to manually
declutter to prevent memory exhaustion)

Damien

Aug 8 '06 #4

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

Similar topics

6
by: Ross | last post by:
MyWebProject.MyWebForm1.someset.somedata is a datatable within a dataset. Displays quite nicely, too. Now I want to use the same data in MyWebProject.MyWebForm2. Being a old, er, experienced Java...
0
by: VB Programmer | last post by:
I wanted to access some properties of a panel control that is on a different form. So, I went to the (Declarations) section of my main form (the form with the panel) and changed the panel (called...
2
by: John Granade | last post by:
I'm looking for the best way to make a dataset available from multiple Windows forms. The dataset is created from an XML file. I have a main form (frmMain) that loads the dataset and reads the...
1
by: David Sanschagrin | last post by:
(I previously posted this problem on vb.general.discussion but I've been told that this question is more related to VB.NET than VB6 and so that I should post that here.) I'm trying to call a...
1
by: timbobd | last post by:
I have encountered a situation that I don't understand. When I call a sub of Friend scope (in an object with Friend scope), I am getting an error "Public member 'subname' not found in type...
7
by: Carsten H. Pedersen | last post by:
Hello I want to create a kind of shared object. I have created a class, Counter, which you can then import. Through the Counter class, i would like to have access to a shared object. Lets say...
2
by: HmFireBall | last post by:
Hi, This is a question about a shared property in ASP.NET Imagine there's an assembly called my.dll that is in the /bin directory of several websites. This assembly contains a class with a...
0
by: AndyB | last post by:
I'm using xsd.exe to generate a typed-dataset. Then using typed dataset tables (datatables containing two columns--a name and a value) to bind to ASP.NET dropdown list controls (for the dropdown...
7
by: LoneHunter01 | last post by:
When I try to compile the below files, the complier says: the WordNode h in BST.cpp: "WordNode" does not name a type also in BST.cpp: "WordNode" undeclared, first use of this function So, any...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.