473,387 Members | 3,684 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,387 software developers and data experts.

Global property

I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks
Nov 18 '05 #1
15 2485
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
....
End Sub

....
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the specific
type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks

Nov 18 '05 #2
Karl,

This is quite interesting. But something doesn't seem right to me. A
usercontrol can be placed on any page. Won't this cause problems if you try
and cast the Page object it is "hosted" in to a specific class?

Problems may not be the right word. Shouldn't you do some sort of test to
be sure Page is of the correct type before casting?

If TypeOf (Page) Is WebForm1 Then
dim pageValue as string = ctype(Page, WebForm1).MyValue
End If

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ew****************@TK2MSFTNGP14.phx.gbl...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the specific type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks


Nov 18 '05 #3
Yes,
Your problem statement didn't mention that.

If you need this from multiple page, the best solution is to make them
implement an interface and cast the page to said interface...if this is what
you need, lemme know.

Karl

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP14.phx.gbl...
Karl,

This is quite interesting. But something doesn't seem right to me. A
usercontrol can be placed on any page. Won't this cause problems if you try and cast the Page object it is "hosted" in to a specific class?

Problems may not be the right word. Shouldn't you do some sort of test to
be sure Page is of the correct type before casting?

If TypeOf (Page) Is WebForm1 Then
dim pageValue as string = ctype(Page, WebForm1).MyValue
End If

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ew****************@TK2MSFTNGP14.phx.gbl...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the

specific
type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks



Nov 18 '05 #4
Sorry Greg,..just realized you aren't the one who asked the original
question ... :)

Karl
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP14.phx.gbl...
Karl,

This is quite interesting. But something doesn't seem right to me. A
usercontrol can be placed on any page. Won't this cause problems if you try and cast the Page object it is "hosted" in to a specific class?

Problems may not be the right word. Shouldn't you do some sort of test to
be sure Page is of the correct type before casting?

If TypeOf (Page) Is WebForm1 Then
dim pageValue as string = ctype(Page, WebForm1).MyValue
End If

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ew****************@TK2MSFTNGP14.phx.gbl...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the

specific
type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks



Nov 18 '05 #5
Ah, but I would love to see how to do that (the interface design) if you get
a chance. I have an app that utilizes a few user controls across a couple
of webforms. They all need to share the same state. My current method is
extremely ugly. I've made all the user controls have a public property (say
MySettings). In the page load I initialize all the usercontrols MySettings
properties to match the Page's MySettings. Every time there is a change, I
resync all the usercontrols (by raising custom events registered in the
hosting Page). It is very ugly as you can imagine.

I probably should have just shoved MySettings into a Session variable, but I
was trying to keep everything in ViewState instead. (Not sure I am made the
right decision here)

It is very interesting to me to be able to read a common property from the
hosting page directly. My problem is, like I mentioned, my usercontrols are
spread across mutliple webforms and doing a Select Case on a TypeOf seems
uglier yet.

Greg
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:e4***************@tk2msftngp13.phx.gbl...
Sorry Greg,..just realized you aren't the one who asked the original
question ... :)

Karl
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP14.phx.gbl...
Karl,

This is quite interesting. But something doesn't seem right to me. A
usercontrol can be placed on any page. Won't this cause problems if you

try
and cast the Page object it is "hosted" in to a specific class?

Problems may not be the right word. Shouldn't you do some sort of test to be sure Page is of the correct type before casting?

If TypeOf (Page) Is WebForm1 Then
dim pageValue as string = ctype(Page, WebForm1).MyValue
End If

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:ew****************@TK2MSFTNGP14.phx.gbl...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the

specific
type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
> I have main aspx page with a number of user controls.
> How can I create a global property that will be visible in every user > control?
>
> Thanks
>
>



Nov 18 '05 #6
You can either do it with a base page or an interface.

Public Interface ISettings
ReadOnly Property Settings() As Hashtable
End Interface

your pages:

Public Class TestPage
Inherits Page
Implements ISettings

private _settings as Hashtable
Public ReadOnly Property Settings() As Hashtable Implements
ISettings.Settings
Get
return _settings
End Get
End Property
...
End Class

Public Class TestPage2
Inherits Page
Implements ISettings

private _settings as Hashtable
Public ReadOnly Property Settings() As Hashtable Implements
ISettings.Settings
Get
return _settings
End Get
End Property
...
End Class

your user control:

if typeof (Page) is ISettings then
settings = ctype(Page, ISettings).Settings
end if
Is that what you wanted?

Karl

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:eZ**************@TK2MSFTNGP09.phx.gbl...
Ah, but I would love to see how to do that (the interface design) if you get a chance. I have an app that utilizes a few user controls across a couple
of webforms. They all need to share the same state. My current method is
extremely ugly. I've made all the user controls have a public property (say MySettings). In the page load I initialize all the usercontrols MySettings properties to match the Page's MySettings. Every time there is a change, I resync all the usercontrols (by raising custom events registered in the
hosting Page). It is very ugly as you can imagine.

I probably should have just shoved MySettings into a Session variable, but I was trying to keep everything in ViewState instead. (Not sure I am made the right decision here)

It is very interesting to me to be able to read a common property from the
hosting page directly. My problem is, like I mentioned, my usercontrols are spread across mutliple webforms and doing a Select Case on a TypeOf seems
uglier yet.

Greg
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:e4***************@tk2msftngp13.phx.gbl...
Sorry Greg,..just realized you aren't the one who asked the original
question ... :)

Karl
"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:uD**************@TK2MSFTNGP14.phx.gbl...
Karl,

This is quite interesting. But something doesn't seem right to me. A
usercontrol can be placed on any page. Won't this cause problems if
you
try
and cast the Page object it is "hosted" in to a specific class?

Problems may not be the right word. Shouldn't you do some sort of
test to be sure Page is of the correct type before casting?

If TypeOf (Page) Is WebForm1 Then
dim pageValue as string = ctype(Page, WebForm1).MyValue
End If

Greg

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:ew****************@TK2MSFTNGP14.phx.gbl...
> create a public property
>
> Say your page is of type WebForm1
>
> Public Class WebForm1
> inherits System.Web.UI.Page
>
>
> private _myvalue as string = "SomeValue"
> public readonly property MyValue() as string
> get
> return _myvalue
> end get
> end property
>
> Sub Page Load...
> ...
> End Sub
>
> ...
> End class
>
> In your user controls, you can access MyValue via:
>
> dim pageValue as string = ctype(Page, WebForm1).MyValue
>
>
> Every user control has access to the Page, and by casting it to the
specific
> type, you have access to it's public property/methods..
>
> Karl
>
>
> "Mark Goldin" <ma********@comcast.net> wrote in message
> news:eH****************@TK2MSFTNGP12.phx.gbl...
> > I have main aspx page with a number of user controls.
> > How can I create a global property that will be visible in every user > > control?
> >
> > Thanks
> >
> >
>
>



Nov 18 '05 #7
I believe so. Thanks!

Greg

Is that what you wanted?

Karl

Nov 18 '05 #8
How do I reference such a property from a user control?

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ew**************@TK2MSFTNGP14.phx.gbl...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the specific type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
I have main aspx page with a number of user controls.
How can I create a global property that will be visible in every user
control?

Thanks


Nov 18 '05 #9
In your usercontrol, you just do like Karl says:

dim pageValue as string = ctype(Page, WebForm1).MyValue

where MyValue is a property of your WebForm1 class

Now, if you go the extra mile and make your WebForm1 implement an interface
(says ISettings), then you can do this:

dim pageValue as string = ctype(Page, ISettings).MyValue

Which is more generic and useful.

Let me know if you need more help. Not sure about the language barrier.
(I'm a VB'er)
Greg
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
How do I reference such a property from a user control?

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:ew**************@TK2MSFTNGP14.phx.gbl...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the

specific
type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
> I have main aspx page with a number of user controls.
> How can I create a global property that will be visible in every user
> control?
>
> Thanks
>
>



Nov 18 '05 #10
I have no idea how to do that in C#.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
In your usercontrol, you just do like Karl says:

dim pageValue as string = ctype(Page, WebForm1).MyValue

where MyValue is a property of your WebForm1 class

Now, if you go the extra mile and make your WebForm1 implement an interface (says ISettings), then you can do this:

dim pageValue as string = ctype(Page, ISettings).MyValue

Which is more generic and useful.

Let me know if you need more help. Not sure about the language barrier.
(I'm a VB'er)
Greg
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
How do I reference such a property from a user control?

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:ew**************@TK2MSFTNGP14.phx.gbl...
create a public property

Say your page is of type WebForm1

Public Class WebForm1
inherits System.Web.UI.Page
private _myvalue as string = "SomeValue"
public readonly property MyValue() as string
get
return _myvalue
end get
end property

Sub Page Load...
...
End Sub

...
End class

In your user controls, you can access MyValue via:

dim pageValue as string = ctype(Page, WebForm1).MyValue
Every user control has access to the Page, and by casting it to the

specific
type, you have access to it's public property/methods..

Karl
"Mark Goldin" <ma********@comcast.net> wrote in message
news:eH****************@TK2MSFTNGP12.phx.gbl...
> I have main aspx page with a number of user controls.
> How can I create a global property that will be visible in every user
> control?
>
> Thanks
>
>



Nov 18 '05 #11
That makes two of us. :^)

Greg

"Mark Goldin" <ma********@comcast.net> wrote in message
news:OZ****************@TK2MSFTNGP14.phx.gbl...
I have no idea how to do that in C#.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
In your usercontrol, you just do like Karl says:

dim pageValue as string = ctype(Page, WebForm1).MyValue

where MyValue is a property of your WebForm1 class

Now, if you go the extra mile and make your WebForm1 implement an

interface
(says ISettings), then you can do this:

dim pageValue as string = ctype(Page, ISettings).MyValue

Which is more generic and useful.

Let me know if you need more help. Not sure about the language barrier.
(I'm a VB'er)
Greg
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
> How do I reference such a property from a user control?
>
> "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in > message news:ew**************@TK2MSFTNGP14.phx.gbl...
>> create a public property
>>
>> Say your page is of type WebForm1
>>
>> Public Class WebForm1
>> inherits System.Web.UI.Page
>>
>>
>> private _myvalue as string = "SomeValue"
>> public readonly property MyValue() as string
>> get
>> return _myvalue
>> end get
>> end property
>>
>> Sub Page Load...
>> ...
>> End Sub
>>
>> ...
>> End class
>>
>> In your user controls, you can access MyValue via:
>>
>> dim pageValue as string = ctype(Page, WebForm1).MyValue
>>
>>
>> Every user control has access to the Page, and by casting it to the
> specific
>> type, you have access to it's public property/methods..
>>
>> Karl
>>
>>
>> "Mark Goldin" <ma********@comcast.net> wrote in message
>> news:eH****************@TK2MSFTNGP12.phx.gbl...
>> > I have main aspx page with a number of user controls.
>> > How can I create a global property that will be visible in every
>> > user
>> > control?
>> >
>> > Thanks
>> >
>> >
>>
>>
>
>



Nov 18 '05 #12

string pageValue = ((WebForm1)Page).MyValue

or via the interface:

string pageValue ((ISettings)Page).MyValue

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OZ****************@TK2MSFTNGP14.phx.gbl...
I have no idea how to do that in C#.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
In your usercontrol, you just do like Karl says:

dim pageValue as string = ctype(Page, WebForm1).MyValue

where MyValue is a property of your WebForm1 class

Now, if you go the extra mile and make your WebForm1 implement an

interface
(says ISettings), then you can do this:

dim pageValue as string = ctype(Page, ISettings).MyValue

Which is more generic and useful.

Let me know if you need more help. Not sure about the language barrier.
(I'm a VB'er)
Greg
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
How do I reference such a property from a user control?

"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:ew**************@TK2MSFTNGP14.phx.gbl...
> create a public property
>
> Say your page is of type WebForm1
>
> Public Class WebForm1
> inherits System.Web.UI.Page
>
>
> private _myvalue as string = "SomeValue"
> public readonly property MyValue() as string
> get
> return _myvalue
> end get
> end property
>
> Sub Page Load...
> ...
> End Sub
>
> ...
> End class
>
> In your user controls, you can access MyValue via:
>
> dim pageValue as string = ctype(Page, WebForm1).MyValue
>
>
> Every user control has access to the Page, and by casting it to the
specific
> type, you have access to it's public property/methods..
>
> Karl
>
>
> "Mark Goldin" <ma********@comcast.net> wrote in message
> news:eH****************@TK2MSFTNGP12.phx.gbl...
> > I have main aspx page with a number of user controls.
> > How can I create a global property that will be visible in every user> > control?
> >
> > Thanks
> >
> >
>
>



Nov 18 '05 #13
After all here is what I have:
in Webform (main2):
private DataSet _Employee = null;

public DataSet Employee

{

get

{return _Employee;}

set

{_Employee = value;}

}

in the user control:

DataSet ds = ((humanres.main2)Page).Employee;

....

SqlHelper.FillDataset(conn, CommandType.Text, "select * from udf_getEmployeeDetails(" + EmployeeId + ")",

ds, new string[]{"employee"});

fails with the following error:



Server Error in '/humanres' Application.
--------------------------------------------------------------------------------

Value cannot be null. Parameter name: dataSet
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: dataSet
Line 53: DataSet ds = ((humanres.main2)Page).Employee;
.....

Line 55: SqlHelper.FillDataset(conn, CommandType.Text, "select * from udf_getEmployeeDetails(" + EmployeeId + ")",
Line 56: ds, new string[]{"employee"});


"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eV**************@TK2MSFTNGP11.phx.gbl...

string pageValue = ((WebForm1)Page).MyValue

or via the interface:

string pageValue ((ISettings)Page).MyValue

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Mark Goldin" <ma********@comcast.net> wrote in message
news:OZ****************@TK2MSFTNGP14.phx.gbl...
I have no idea how to do that in C#.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
In your usercontrol, you just do like Karl says:

dim pageValue as string = ctype(Page, WebForm1).MyValue

where MyValue is a property of your WebForm1 class

Now, if you go the extra mile and make your WebForm1 implement an

interface
(says ISettings), then you can do this:

dim pageValue as string = ctype(Page, ISettings).MyValue

Which is more generic and useful.

Let me know if you need more help. Not sure about the language barrier.
(I'm a VB'er)
Greg
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
> How do I reference such a property from a user control?
>
> "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote

in
> message news:ew**************@TK2MSFTNGP14.phx.gbl...
>> create a public property
>>
>> Say your page is of type WebForm1
>>
>> Public Class WebForm1
>> inherits System.Web.UI.Page
>>
>>
>> private _myvalue as string = "SomeValue"
>> public readonly property MyValue() as string
>> get
>> return _myvalue
>> end get
>> end property
>>
>> Sub Page Load...
>> ...
>> End Sub
>>
>> ...
>> End class
>>
>> In your user controls, you can access MyValue via:
>>
>> dim pageValue as string = ctype(Page, WebForm1).MyValue
>>
>>
>> Every user control has access to the Page, and by casting it to the
> specific
>> type, you have access to it's public property/methods..
>>
>> Karl
>>
>>
>> "Mark Goldin" <ma********@comcast.net> wrote in message
>> news:eH****************@TK2MSFTNGP12.phx.gbl...
>> > I have main aspx page with a number of user controls.
>> > How can I create a global property that will be visible in every user >> > control?
>> >
>> > Thanks
>> >
>> >
>>
>>
>
>



Nov 18 '05 #14
Mark,
Your dataset is null...you never do _Employee = new DataSet()...The simplest
way to solve your problem:

private DataSet _Employee = new DataSet(); //instead of = null;

The reason no on suggested this is that declaring a dataset in a page and
populating it in a user-control isn't obvious (at best) and suspect (at
worst). I would consider examining if that's a sound architecture. Since
I'm not sure what you are trying to do, short of your initial post asking
how to make a variable visible to all user controls, I can't offer any
suggestions.

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mark Goldin" <ma********@comcast.net> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl...
After all here is what I have:
in Webform (main2):
private DataSet _Employee = null;
public DataSet Employee
{
get
{return _Employee;}
set
{_Employee = value;}
}
in the user control:
DataSet ds = ((humanres.main2)Page).Employee;
....
SqlHelper.FillDataset(conn, CommandType.Text, "select * from
udf_getEmployeeDetails(" + EmployeeId + ")",
ds, new string[]{"employee"});
fails with the following error:
Server Error in '/humanres' Application.
Value cannot be null. Parameter name: dataSet
Description: An unhandled exception occurred during the execution of the
current web request. Please review the stack trace for more information
about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null.
Parameter name: dataSet

Line 53: DataSet ds = ((humanres.main2)Page).Employee;
.....
Line 55: SqlHelper.FillDataset(conn, CommandType.Text, "select * from
udf_getEmployeeDetails(" + EmployeeId + ")",
Line 56: ds, new string[]{"employee"});
"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in
message news:eV**************@TK2MSFTNGP11.phx.gbl...

string pageValue = ((WebForm1)Page).MyValue

or via the interface:

string pageValue ((ISettings)Page).MyValue

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OZ****************@TK2MSFTNGP14.phx.gbl...
I have no idea how to do that in C#.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
In your usercontrol, you just do like Karl says:

dim pageValue as string = ctype(Page, WebForm1).MyValue

where MyValue is a property of your WebForm1 class

Now, if you go the extra mile and make your WebForm1 implement an

interface
(says ISettings), then you can do this:

dim pageValue as string = ctype(Page, ISettings).MyValue

Which is more generic and useful.

Let me know if you need more help. Not sure about the language barrier. (I'm a VB'er)
Greg
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
> How do I reference such a property from a user control?
>
> "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote
in
> message news:ew**************@TK2MSFTNGP14.phx.gbl...
>> create a public property
>>
>> Say your page is of type WebForm1
>>
>> Public Class WebForm1
>> inherits System.Web.UI.Page
>>
>>
>> private _myvalue as string = "SomeValue"
>> public readonly property MyValue() as string
>> get
>> return _myvalue
>> end get
>> end property
>>
>> Sub Page Load...
>> ...
>> End Sub
>>
>> ...
>> End class
>>
>> In your user controls, you can access MyValue via:
>>
>> dim pageValue as string = ctype(Page, WebForm1).MyValue
>>
>>
>> Every user control has access to the Page, and by casting it to the
> specific
>> type, you have access to it's public property/methods..
>>
>> Karl
>>
>>
>> "Mark Goldin" <ma********@comcast.net> wrote in message
>> news:eH****************@TK2MSFTNGP12.phx.gbl...
>> > I have main aspx page with a number of user controls.
>> > How can I create a global property that will be visible in every

user >> > control?
>> >
>> > Thanks
>> >
>> >
>>
>>
>
>



Nov 18 '05 #15
Your ds that your are passing to SqlHelper.Fill is still null. It has never been istantiated.

The VB equivalent is you have this: (not sure have to express this in c#)

Dim conn As New SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("ConnectionString"))
Dim ds As DataSet
SqlHelper.FillDataset(conn, CommandType.Text, "select * from users where empid=1", ds, New String() {"employee"})

You need to have this:
Dim conn As New SqlClient.SqlConnection(ConfigurationSettings.AppS ettings("ConnectionString"))
Dim ds As NEW DataSet ' <---- gotta istantiate it first!!!
SqlHelper.FillDataset(conn, CommandType.Text, "select * from users where empid=1", ds, New String() {"employee"})
The reason your dataset is null, is becuase you assign it to the Employee ds property of your webform. And your not showing any code where you istantiate it anywhere.

These little bits and pieces of code without context are not helping me. (Maybe somebody else can help out here... please!)

Greg

"Mark Goldin" <ma********@comcast.net> wrote in message news:%2****************@TK2MSFTNGP09.phx.gbl...
After all here is what I have:
in Webform (main2):
private DataSet _Employee = null;

public DataSet Employee

{

get

{return _Employee;}

set

{_Employee = value;}

}

in the user control:

DataSet ds = ((humanres.main2)Page).Employee;

...

SqlHelper.FillDataset(conn, CommandType.Text, "select * from udf_getEmployeeDetails(" + EmployeeId + ")",

ds, new string[]{"employee"});

fails with the following error:
Server Error in '/humanres' Application.
------------------------------------------------------------------------------

Value cannot be null. Parameter name: dataSet
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.ArgumentNullException: Value cannot be null. Parameter name: dataSet
Line 53: DataSet ds = ((humanres.main2)Page).Employee;
....

Line 55: SqlHelper.FillDataset(conn, CommandType.Text, "select * from udf_getEmployeeDetails(" + EmployeeId + ")",
Line 56: ds, new string[]{"employee"});


"Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote in message news:eV**************@TK2MSFTNGP11.phx.gbl...

string pageValue = ((WebForm1)Page).MyValue

or via the interface:

string pageValue ((ISettings)Page).MyValue

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/


"Mark Goldin" <ma********@comcast.net> wrote in message
news:OZ****************@TK2MSFTNGP14.phx.gbl...
I have no idea how to do that in C#.

"Greg Burns" <greg_burns@DONT_SPAM_ME_hotmail.com> wrote in message
news:OV**************@tk2msftngp13.phx.gbl...
In your usercontrol, you just do like Karl says:

dim pageValue as string = ctype(Page, WebForm1).MyValue

where MyValue is a property of your WebForm1 class

Now, if you go the extra mile and make your WebForm1 implement an

interface
(says ISettings), then you can do this:

dim pageValue as string = ctype(Page, ISettings).MyValue

Which is more generic and useful.

Let me know if you need more help. Not sure about the language barrier.
(I'm a VB'er)
Greg
"Mark Goldin" <ma********@comcast.net> wrote in message
news:OT**************@TK2MSFTNGP11.phx.gbl...
> How do I reference such a property from a user control?
>
> "Karl" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net> wrote

in
> message news:ew**************@TK2MSFTNGP14.phx.gbl...
>> create a public property
>>
>> Say your page is of type WebForm1
>>
>> Public Class WebForm1
>> inherits System.Web.UI.Page
>>
>>
>> private _myvalue as string = "SomeValue"
>> public readonly property MyValue() as string
>> get
>> return _myvalue
>> end get
>> end property
>>
>> Sub Page Load...
>> ...
>> End Sub
>>
>> ...
>> End class
>>
>> In your user controls, you can access MyValue via:
>>
>> dim pageValue as string = ctype(Page, WebForm1).MyValue
>>
>>
>> Every user control has access to the Page, and by casting it to the
> specific
>> type, you have access to it's public property/methods..
>>
>> Karl
>>
>>
>> "Mark Goldin" <ma********@comcast.net> wrote in message
>> news:eH****************@TK2MSFTNGP12.phx.gbl...
>> > I have main aspx page with a number of user controls.
>> > How can I create a global property that will be visible in every user >> > control?
>> >
>> > Thanks
>> >
>> >
>>
>>
>
>



Nov 18 '05 #16

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

Similar topics

2
by: Aaron | last post by:
Hi, I've seen javascript code where a constructor function is passed an argument "document", and inside the function itself the assignment "this.document = document;" is made. This is the code...
8
by: lawrence | last post by:
I'm learning Javascript. I downloaded a script for study. Please tell me how the variable "loop" can have scope in the first function when it is altered in the second function? It is not defined...
3
by: Steve | last post by:
Visual Studio 2003 / C# My application has 1 main form. On this form is a treeview object down the left hand edge and a status bar along the bottom. That is all. The tree view acts as my menu...
33
by: MLH | last post by:
I've read some posts indicating that having tons of GV's in an Access app is a bad idea. Personally, I love GVs and I use them (possibly abuse them) all the time for everything imaginable - have...
16
by: Roman Ziak | last post by:
Hello, there were times when I used to be looking for a way to access JavaScript Global object similar to those found in VBScript or PHP ($GLOBALS). At present this has only academic value for...
23
by: David Colliver | last post by:
Hi, using c#, 1.1 I know that we are not supposed to use global variables etc. in c# I am having a problem, but not sure how to resolve. I did have another post here, but may have over...
3
by: User1014 | last post by:
A global variable is really just a property of the "Global Object", so what does that make a function defined in the global context? A method of the Global Object? ...
3
by: rusdyrip | last post by:
hi all, anyone to know how to make Global Property so if i change Font size, all form on my application will change did i must change the designer every form? thx
15
by: Bob | last post by:
Is there anyway to access the global object from inside a function other than doing a "var _global = this;" before declaring the function? Thanks
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.