472,780 Members | 1,653 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,780 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 2174
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: Rina0 | last post by:
Cybersecurity engineering is a specialized field that focuses on the design, development, and implementation of systems, processes, and technologies that protect against cyber threats and...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
by: erikbower65 | last post by:
Here's a concise step-by-step guide for manually installing IntelliJ IDEA: 1. Download: Visit the official JetBrains website and download the IntelliJ IDEA Community or Ultimate edition based on...
0
by: Rina0 | last post by:
I am looking for a Python code to find the longest common subsequence of two strings. I found this blog post that describes the length of longest common subsequence problem and provides a solution in...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: lllomh | last post by:
How does React native implement an English player?
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

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.