473,883 Members | 1,635 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.P age
Friend Shared _oRpte As ReportClass
......
' more code
......
Private Sub MyFunction()
Dim oRpt As New MyCrystalReport
oRpt.SetDataSou rce(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.SetParame terValue("param 1", strMessageOnRap port)
'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 2275
jb*****@gmail.c om 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"),ReportC lass)]. 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
1463
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 programmer, I thought I could write this as a member of MyWebForm1: Public Shared Function getSomeData() As DataTable getSomeData = somedata End Function
0
1481
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 "panKnob") from "Friend WithEvents" to "Public Shared WithEvents" so that I could access it from another class (i.e. frmMain.panKnob.Visible=True") I get this build error: "The variable 'panKnob' is either undeclared or was never assigned." ...
2
6908
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 data but then I have other forms that give the ability to add, modify, and delete rows. This of course changes the dataset and I need that reflected in the main form. At first I was actually passing a reference of the dataset to the "modify" form...
1
6789
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 "Public Shared" function in a dll built in VB.NET from a VB6 program. Whenever I try, I get an error saying that the function doesnt exist. I had doubts that the "Shared" in the VB.NET dll could be the problem. I tried to
1
2241
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 'myType'". Any idea why? Since Friend scope should be visible within my assembly, and everying is taking place within a single project, I don't understand why this error is occuring. Here is some illustrative code, where I would get the error in the...
7
7360
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 that Counter contains only an int, initialised to 1. Each time a class importing Counter would do Counter.getNextNumber(), the getNextNumber() method would increase the local int, and return the next number.
2
1561
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 shared property called MySharedProp. Its value is initialized inside the shared constructor of the class and should be based on values declared in the web.config of
0
1622
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 list option values). All was fine with the binding, until I moved the dataset to a different assembly, as I found out that the DataColumn property is "Friend" (in VB.NET). Could you point me how to make the DataColumn "public", or another work...
7
2711
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 advice? Sorry for the huge post, just wanted to make sure you can understand the problem. As it is, I'm lost.... I've included the WordNode header file, so why can't I create/use WordNode objects/methods (in BST)? WordNode.h #ifndef RANDOM...
0
9933
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11114
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10730
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10835
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9563
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7960
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5787
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4605
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4205
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.