469,613 Members | 1,270 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,613 developers. It's quick & easy.

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 2057
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Kevin Phifer | last post: by
2 posts views Thread by jaffar.kazi | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.