473,465 Members | 1,395 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Page.FindControl non-Shared member

I have a .ascx file that I converted to a class.

But I am getting the following error:

error BC30469: Reference to a non-shared member requires an object
reference.

The error is for the Page.FindControl in the following code:

******************************************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Collections

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label = CType(Page.FindControl("UserLoggedOn"),Label)
Dim UserLoggedOnLabel as Label =
CType(Page.FindControl("UserLoggedOnLabel"),Label)
if not UserLoggedOn is nothing then
if HttpContext.Current.session("LoggedIn") <nothing then
if HttpContext.Current.session("firstName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text &
HttpContext.Current.session("firstName")
if HttpContext.Current.session("lastName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text & " " &
HttpContext.Current.session("lastName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.visible = true
if not UserLoggedOnLabel is nothing then UserLoggedOnLabel.visible =
true
end if
end if
end if
if not HttpContext.Current.session("User") is nothing then _
HttpContext.Current.session("LastPageVisited") =
HttpContext.Current.Session("User").LastPageVisite d
End Sub
End Class
End Namespace
************************************************** ***********************

Why am I getting this error?

Do I need something in front the Page.FindControl?

Thanks,

Tom


Aug 16 '06 #1
3 2191
Page is a class. It is not an instance of that class. You should pass in a
variable to your PageSetup routine, which is an instance of the page it
should set up.

In a .ascx, Page is a property of the class, hence you can use it. When you
are just in a function in some other class, it doesn't have such a property.

"tshad" <ts**********@ftsolutions.comwrote in message
news:u2**************@TK2MSFTNGP04.phx.gbl...
>I have a .ascx file that I converted to a class.

But I am getting the following error:

error BC30469: Reference to a non-shared member requires an object
reference.

The error is for the Page.FindControl in the following code:

******************************************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Collections

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label =
CType(Page.FindControl("UserLoggedOn"),Label)
Dim UserLoggedOnLabel as Label =
CType(Page.FindControl("UserLoggedOnLabel"),Label)
if not UserLoggedOn is nothing then
if HttpContext.Current.session("LoggedIn") <nothing then
if HttpContext.Current.session("firstName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text &
HttpContext.Current.session("firstName")
if HttpContext.Current.session("lastName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text & " " &
HttpContext.Current.session("lastName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.visible = true
if not UserLoggedOnLabel is nothing then UserLoggedOnLabel.visible =
true
end if
end if
end if
if not HttpContext.Current.session("User") is nothing then _
HttpContext.Current.session("LastPageVisited") =
HttpContext.Current.Session("User").LastPageVisite d
End Sub
End Class
End Namespace
************************************************** ***********************

Why am I getting this error?

Do I need something in front the Page.FindControl?

Thanks,

Tom


Aug 16 '06 #2
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:OJ**************@TK2MSFTNGP04.phx.gbl...
Page is a class. It is not an instance of that class. You should pass in
a variable to your PageSetup routine, which is an instance of the page it
should set up.

In a .ascx, Page is a property of the class, hence you can use it. When
you are just in a function in some other class, it doesn't have such a
property.
Would I then do the following in the function:
************************************************** ************
NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup (thePage as Page)
Dim UserLoggedOn as Label =
CType(thePage.FindControl("UserLoggedOn"),Label)
Dim UserLoggedOnLabel as Label =
CType(thePage.FindControl("UserLoggedOnLabel"),Lab el)
************************************************** *********************

And then call it as:

MyFunctions.PageInit.PageSetup(Page)

Thanks,

Tom
>
"tshad" <ts**********@ftsolutions.comwrote in message
news:u2**************@TK2MSFTNGP04.phx.gbl...
>>I have a .ascx file that I converted to a class.

But I am getting the following error:

error BC30469: Reference to a non-shared member requires an object
reference.

The error is for the Page.FindControl in the following code:

******************************************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Collections

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label =
CType(Page.FindControl("UserLoggedOn"),Label)
Dim UserLoggedOnLabel as Label =
CType(Page.FindControl("UserLoggedOnLabel"),Label )
if not UserLoggedOn is nothing then
if HttpContext.Current.session("LoggedIn") <nothing then
if HttpContext.Current.session("firstName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text &
HttpContext.Current.session("firstName")
if HttpContext.Current.session("lastName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text & " " &
HttpContext.Current.session("lastName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.visible = true
if not UserLoggedOnLabel is nothing then UserLoggedOnLabel.visible =
true
end if
end if
end if
if not HttpContext.Current.session("User") is nothing then _
HttpContext.Current.session("LastPageVisited") =
HttpContext.Current.Session("User").LastPageVisit ed
End Sub
End Class
End Namespace
************************************************* ************************

Why am I getting this error?

Do I need something in front the Page.FindControl?

Thanks,

Tom



Aug 16 '06 #3
"Marina Levit [MVP]" <so*****@nospam.comwrote in message
news:OJ**************@TK2MSFTNGP04.phx.gbl...
Page is a class. It is not an instance of that class. You should pass in
a variable to your PageSetup routine, which is an instance of the page it
should set up.

In a .ascx, Page is a property of the class, hence you can use it. When
you are just in a function in some other class, it doesn't have such a
property.
Here is how I set it up and it works great.

****************************************
NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup (thePage as Page)
Dim url as String
Dim urlNoParams as String
Dim UserLoggedOn as Label =
CType(thePage.FindControl("UserLoggedOn"),Label)
Dim UserLoggedOnLabel as Label =
CType(thePage.FindControl("UserLoggedOnLabel"),Lab el)
if not UserLoggedOn is nothing then
if HttpContext.Current.session("LoggedIn") <nothing then
if HttpContext.Current.session("firstName") <nothing then

************************************************** *****

I call it like so:

<%@ Import Namespace="MyFunctions" %>

<script runat="server">
Sub Page_Load(sender as Object, e as EventArgs)
if not IsPostBack
PageInit.PageSetup(Page)

Why do I need to send it the "Page" but not the Session Variables? Isn't
there a direct way to access it as the current Page?

Thanks,

Tom
>
"tshad" <ts**********@ftsolutions.comwrote in message
news:u2**************@TK2MSFTNGP04.phx.gbl...
>>I have a .ascx file that I converted to a class.

But I am getting the following error:

error BC30469: Reference to a non-shared member requires an object
reference.

The error is for the Page.FindControl in the following code:

******************************************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.SessionState
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.HttpCookie
Imports System.Web.HttpCookieCollection
Imports System.Web.HttpResponse
Imports System.Web.HttpRequest
imports System.Web.HttpContext
Imports System.Web.HttpApplication
Imports System.Web.HttpApplicationState
Imports System.Collections

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label =
CType(Page.FindControl("UserLoggedOn"),Label)
Dim UserLoggedOnLabel as Label =
CType(Page.FindControl("UserLoggedOnLabel"),Label )
if not UserLoggedOn is nothing then
if HttpContext.Current.session("LoggedIn") <nothing then
if HttpContext.Current.session("firstName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text &
HttpContext.Current.session("firstName")
if HttpContext.Current.session("lastName") <nothing then
UserLoggedOn.Text = UserLoggedOn.Text & " " &
HttpContext.Current.session("lastName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.visible = true
if not UserLoggedOnLabel is nothing then UserLoggedOnLabel.visible =
true
end if
end if
end if
if not HttpContext.Current.session("User") is nothing then _
HttpContext.Current.session("LastPageVisited") =
HttpContext.Current.Session("User").LastPageVisit ed
End Sub
End Class
End Namespace
************************************************* ************************

Why am I getting this error?

Do I need something in front the Page.FindControl?

Thanks,

Tom



Aug 17 '06 #4

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

Similar topics

4
by: Kevin Phifer | last post by:
Ok, before anyone freaks out, I have a solution I need to create that gathers content from maybe different places. Each one can return a <form> in the html, so its the classic can't have more than...
2
by: sck10 | last post by:
Hello, I am looping through each control using the following to find a particular control (strFindCtl = "tbxCompetitor" & strForLoop1 & "Product"). For ctrRow = 1 To 3 strForLoop1 = "0" &...
2
by: jaffar.kazi | last post by:
Hi, What is the exact name to use to get a control reference on an asp.net page using FindControl? My experience is the following: 1. Page.FindControl does not work; it always returns null, even...
1
by: mark4asp | last post by:
I moved a page to another web-site and now it's broke! I had 5 pages in their own web-site. These pages have now been moved to another web-site. Everything is fine except that one of the pages,...
2
by: pankajsingh5k | last post by:
Dear All, Please help me... I had read an article to lazy load a tab in a tabcontainer using an update panel on http://mattberseth.com/blog/2007/07/how_to_lazyload_tabpanels_with.html ...
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...
1
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...
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...
0
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.