473,811 Members | 3,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Page.FindContro l 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.FindContro l in the following code:

*************** *************** ************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
imports System.Web.Http Context
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports System.Collecti ons

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label = CType(Page.Find Control("UserLo ggedOn"),Label)
Dim UserLoggedOnLab el as Label =
CType(Page.Find Control("UserLo ggedOnLabel"),L abel)
if not UserLoggedOn is nothing then
if HttpContext.Cur rent.session("L oggedIn") <nothing then
if HttpContext.Cur rent.session("f irstName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt &
HttpContext.Cur rent.session("f irstName")
if HttpContext.Cur rent.session("l astName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt & " " &
HttpContext.Cur rent.session("l astName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.vi sible = true
if not UserLoggedOnLab el is nothing then UserLoggedOnLab el.visible =
true
end if
end if
end if
if not HttpContext.Cur rent.session("U ser") is nothing then _
HttpContext.Cur rent.session("L astPageVisited" ) =
HttpContext.Cur rent.Session("U ser").LastPageV isited
End Sub
End Class
End Namespace
*************** *************** *************** *************** *************

Why am I getting this error?

Do I need something in front the Page.FindContro l?

Thanks,

Tom


Aug 16 '06 #1
3 2218
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**********@f tsolutions.comw rote in message
news:u2******** ******@TK2MSFTN GP04.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.FindContro l in the following code:

*************** *************** ************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
imports System.Web.Http Context
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports System.Collecti ons

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label =
CType(Page.Find Control("UserLo ggedOn"),Label)
Dim UserLoggedOnLab el as Label =
CType(Page.Find Control("UserLo ggedOnLabel"),L abel)
if not UserLoggedOn is nothing then
if HttpContext.Cur rent.session("L oggedIn") <nothing then
if HttpContext.Cur rent.session("f irstName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt &
HttpContext.Cur rent.session("f irstName")
if HttpContext.Cur rent.session("l astName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt & " " &
HttpContext.Cur rent.session("l astName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.vi sible = true
if not UserLoggedOnLab el is nothing then UserLoggedOnLab el.visible =
true
end if
end if
end if
if not HttpContext.Cur rent.session("U ser") is nothing then _
HttpContext.Cur rent.session("L astPageVisited" ) =
HttpContext.Cur rent.Session("U ser").LastPageV isited
End Sub
End Class
End Namespace
*************** *************** *************** *************** *************

Why am I getting this error?

Do I need something in front the Page.FindContro l?

Thanks,

Tom


Aug 16 '06 #2
"Marina Levit [MVP]" <so*****@nospam .comwrote in message
news:OJ******** ******@TK2MSFTN GP04.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.F indControl("Use rLoggedOn"),Lab el)
Dim UserLoggedOnLab el as Label =
CType(thePage.F indControl("Use rLoggedOnLabel" ),Label)
*************** *************** *************** *************** ***********

And then call it as:

MyFunctions.Pag eInit.PageSetup (Page)

Thanks,

Tom
>
"tshad" <ts**********@f tsolutions.comw rote in message
news:u2******** ******@TK2MSFTN GP04.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.FindContro l in the following code:

************** *************** *************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
imports System.Web.Http Context
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports System.Collecti ons

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label =
CType(Page.Fin dControl("UserL oggedOn"),Label )
Dim UserLoggedOnLab el as Label =
CType(Page.Fin dControl("UserL oggedOnLabel"), Label)
if not UserLoggedOn is nothing then
if HttpContext.Cur rent.session("L oggedIn") <nothing then
if HttpContext.Cur rent.session("f irstName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt &
HttpContext.Cu rrent.session(" firstName")
if HttpContext.Cur rent.session("l astName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt & " " &
HttpContext.Cu rrent.session(" lastName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.vi sible = true
if not UserLoggedOnLab el is nothing then UserLoggedOnLab el.visible =
true
end if
end if
end if
if not HttpContext.Cur rent.session("U ser") is nothing then _
HttpContext.Cur rent.session("L astPageVisited" ) =
HttpContext.Cu rrent.Session(" User").LastPage Visited
End Sub
End Class
End Namespace
************** *************** *************** *************** **************

Why am I getting this error?

Do I need something in front the Page.FindContro l?

Thanks,

Tom



Aug 16 '06 #3
"Marina Levit [MVP]" <so*****@nospam .comwrote in message
news:OJ******** ******@TK2MSFTN GP04.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.F indControl("Use rLoggedOn"),Lab el)
Dim UserLoggedOnLab el as Label =
CType(thePage.F indControl("Use rLoggedOnLabel" ),Label)
if not UserLoggedOn is nothing then
if HttpContext.Cur rent.session("L oggedIn") <nothing then
if HttpContext.Cur rent.session("f irstName") <nothing then

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

I call it like so:

<%@ Import Namespace="MyFu nctions" %>

<script runat="server">
Sub Page_Load(sende r as Object, e as EventArgs)
if not IsPostBack
PageInit.PageSe tup(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**********@f tsolutions.comw rote in message
news:u2******** ******@TK2MSFTN GP04.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.FindContro l in the following code:

************** *************** *************
Imports System
Imports System.Web
Imports System.IO
Imports System.Web.UI
Imports System.Web.UI.W ebControls
Imports System.Web.Sess ionState
Imports System.Data
Imports System.Data.Sql Client
Imports System.Web.Http Cookie
Imports System.Web.Http CookieCollectio n
Imports System.Web.Http Response
Imports System.Web.Http Request
imports System.Web.Http Context
Imports System.Web.Http Application
Imports System.Web.Http ApplicationStat e
Imports System.Collecti ons

NameSpace MyFunctions

Public Class PageInit

Public Shared sub PageSetup ()
Dim UserLoggedOn as Label =
CType(Page.Fin dControl("UserL oggedOn"),Label )
Dim UserLoggedOnLab el as Label =
CType(Page.Fin dControl("UserL oggedOnLabel"), Label)
if not UserLoggedOn is nothing then
if HttpContext.Cur rent.session("L oggedIn") <nothing then
if HttpContext.Cur rent.session("f irstName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt &
HttpContext.Cu rrent.session(" firstName")
if HttpContext.Cur rent.session("l astName") <nothing then
UserLoggedOn.Te xt = UserLoggedOn.Te xt & " " &
HttpContext.Cu rrent.session(" lastName")
end if
end if
if not UserLoggedOn is nothing then
UserLoggedOn.vi sible = true
if not UserLoggedOnLab el is nothing then UserLoggedOnLab el.visible =
true
end if
end if
end if
if not HttpContext.Cur rent.session("U ser") is nothing then _
HttpContext.Cur rent.session("L astPageVisited" ) =
HttpContext.Cu rrent.Session(" User").LastPage Visited
End Sub
End Class
End Namespace
************** *************** *************** *************** **************

Why am I getting this error?

Do I need something in front the Page.FindContro l?

Thanks,

Tom



Aug 17 '06 #4

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

Similar topics

4
2810
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 one runat=server form on a asp.net page. However, I still want developers to be able to use asp.net controls to create some apps that are created on the page. So I need multiple forms on a asp.net page(doesn't everyone). I purchased the...
2
3912
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" & ctrRow strFindCtl = "tbxCompetitor" & strForLoop1 & "Product" For Each ctlMaster As Control In Page.Controls ' Page If TypeOf ctlMaster Is MasterPage Then '
2
1246
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 if I give the exact control name I'm using, eg. txtFirstName. However, this.FindControl works. 2. There is a page that includes 2 user controls. I'm using AddressControl.ascx and have included it twice on the page as
1
2708
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, which I had trouble with in the past (i.e. same problem), is now partly broke. The paging no longer fully works in the gridview. The gvAwarded_RowDataBound code works to load the ddlPager with the correct number of pages.
2
6976
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 and i am implementing it in my website....
0
9730
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
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10651
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
10392
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
10403
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
10136
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5555
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
4341
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
3868
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.