Thursday, March 22, 2012

structure

what is the best way of sharing a structure among different pages of my
asp.net application?Muhammad,
I assume you mean the Visual style of the pages?
There are a few ways this can be done, I personally use
WilsonMasterPages: -
http://authors.aspalliance.com/Paul...Articles/?id=14
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
Hi,
Try putting the Structure in a separate file to your web pages and making it
'public static' (or 'Public Shared' in VB.NET).
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:%23LYbPYrUEHA.4048@.TK2MSFTNGP12.phx.gbl...
> what is the best way of sharing a structure among different pages of my
> asp.net application?
>
sorry didn't make myself clear, I want to use a data structure and assign
values to its members on different pages and offcourse want to retain all
values assigned on different pages.
"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote i
n
message news:camdst$oni@.odak26.prod.google.com...
> Muhammad,
> I assume you mean the Visual style of the pages?
> There are a few ways this can be done, I personally use
> WilsonMasterPages: -
> http://authors.aspalliance.com/Paul...Articles/?id=14
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com
>
Muhammad,
You could store this structure in the Application object, and update it
there. Although you may have threading issues, so use locking when
accessing it.
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:eFIQYgrUEHA.2388@.TK2MSFTNGP09.phx.gbl...
> sorry didn't make myself clear, I want to use a data structure and assign
> values to its members on different pages and offcourse want to retain all
> values assigned on different pages.
> "Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote
in
> message news:camdst$oni@.odak26.prod.google.com...
>
Is it possible to definte a user defined stucture as application variable.
just of the sake of example
public struct student
{
int id;
string name;
float age;
string address1;
string address2;
}
How can I create an object of student type as an application variable?
"James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
news:e4qMukrUEHA.2520@.TK2MSFTNGP10.phx.gbl...
> Muhammad,
> You could store this structure in the Application object, and update it
> there. Although you may have threading issues, so use locking when
> accessing it.
> James
> "Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
> news:eFIQYgrUEHA.2388@.TK2MSFTNGP09.phx.gbl...
assign
all
in
>
Define the struct as you have in a file within your project. In the
Application_Start event handler in the Global.asax file of your project,
enter the following code:
VB:
Dim oStudent As SomeNamespace.student
' Initialise
oStudent.ID = 0
oStudent.Age = 15
..
' Add the student to the application object
Application("Student") = oStudent
C#:
SomeNamespace.student oStudent;
// Initialise
oStudent.ID = 0;
oStudent.Age = 15;
..
// Add the student to the application object
Application["Student"] = oStudent;
The student struct will then be available to each page. To access it, use
the following code:
VB:
CType(Application("Student"), SomeNamespace.student) ...
C#:
(SomeNamespace.student)Application["Student"] ...
Hope this helps,
James
"Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
news:uTCmXtrUEHA.2972@.TK2MSFTNGP12.phx.gbl...
> Is it possible to definte a user defined stucture as application variable.
> just of the sake of example
> public struct student
> {
> int id;
> string name;
> float age;
> string address1;
> string address2;
> }
> How can I create an object of student type as an application variable?
> "James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
> news:e4qMukrUEHA.2520@.TK2MSFTNGP10.phx.gbl...
> assign
> all
> in
>
Excellent! that make 100% sense, will give it a go now thank you for help.
"James Doran" <jamied1@.NO_SPAMbreathe.com> wrote in message
news:u2jIuzrUEHA.1036@.TK2MSFTNGP12.phx.gbl...
> Define the struct as you have in a file within your project. In the
> Application_Start event handler in the Global.asax file of your project,
> enter the following code:
> VB:
> Dim oStudent As SomeNamespace.student
> ' Initialise
> oStudent.ID = 0
> oStudent.Age = 15
> ...
> ' Add the student to the application object
> Application("Student") = oStudent
> C#:
> SomeNamespace.student oStudent;
> // Initialise
> oStudent.ID = 0;
> oStudent.Age = 15;
> ...
> // Add the student to the application object
> Application["Student"] = oStudent;
> The student struct will then be available to each page. To access it, use
> the following code:
> VB:
> CType(Application("Student"), SomeNamespace.student) ...
> C#:
> (SomeNamespace.student)Application["Student"] ...
> Hope this helps,
> James
> "Muhammad Sheikh" <Muhammad.Sheikh@.4mat.com> wrote in message
> news:uTCmXtrUEHA.2972@.TK2MSFTNGP12.phx.gbl...
variable.
it
retain
wrote
>
Muhammad,
James' sample is great, you might also want to take a look at an
article I put together a while ago on the subject: -
http://aspalliance.com/431
Hth,
Phil Winstanley
Microsoft ASP.NET MVP
http://www.myservicescentral.com
that is extremely helpful. thank you phil.
"Phil Winstanley [Microsoft MVP ASP.NET]" <phil@.winstanley.name> wrote i
n
message news:camn5j$65l@.odak26.prod.google.com...
> Muhammad,
> James' sample is great, you might also want to take a look at an
> article I put together a while ago on the subject: -
> http://aspalliance.com/431
> Hth,
> Phil Winstanley
> Microsoft ASP.NET MVP
> http://www.myservicescentral.com
>

0 comments:

Post a Comment