Current location: Hot Scripts Forums » Programming Languages » ASP.NET » Cannot refer to an instance member of a class from within a shared method or a shared


Cannot refer to an instance member of a class from within a shared method or a shared

Reply
  #1 (permalink)  
Old 09-10-07, 10:41 AM
spyke01 spyke01 is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
Cannot refer to an instance member of a class from within a shared method or a shared

Hi everyone im working on getting an excellent function together for encoding symbols to ascii, the issue im having is that i get an error stating: Name 'Server' is not declared. I have the htmlencode function working on another page, so i tried adding Inherits System.Web.UI.Page to the class but then i get this error: Cannot refer to an instance member of a class from within a shared method or a shared member initializer without an explicit instance of the class.

This file is imported by all the page vb files since it contains several other functions that theyll need its name and code are below:

app_code/functions.vb
vbnet Code:
  1. Imports Microsoft.VisualBasic
  2. Imports System.Data.SqlClient
  3. Imports System.Data
  4. Imports System.Web
  5. Imports Microsoft.Practices.EnterpriseLibrary.Data
  6. Imports Microsoft.Practices.EnterpriseLibrary.Data.Sql
  7.  
  8. Public Class functions
  9.     Inherits System.Web.UI.Page
  10.     '===================================================================
  11.     ' Helper function to encode characters, this will be used with the
  12.     ' special helper functions that accomodate DAAB, use these functions
  13.     ' everytime data hits a database or is printed to the screen.
  14.     ' Preferablly as soon as you get the data and before any checkers
  15.     '===================================================================
  16.     Public Shared Function makeSafe(ByVal strToSanitize As String) As String
  17.         Dim sanitizedStr As String
  18.  
  19.         ' Convert symbols into ascii
  20.         sanitizedStr = Replace(strToSanitize, ";", ";")
  21.         sanitizedStr = Server.HtmlEncode(sanitizedStr)
  22.         sanitizedStr = Replace(sanitizedStr, "'", "'")
  23.         sanitizedStr = Replace(sanitizedStr, """", """)
  24.         sanitizedStr = Replace(sanitizedStr, "-", "-")
  25.         sanitizedStr = Replace(sanitizedStr, "+", "+")
  26.         sanitizedStr = Replace(sanitizedStr, "=", "=")
  27.         sanitizedStr = Replace(sanitizedStr, ":", ":")
  28.         sanitizedStr = Replace(sanitizedStr, "(", "(")
  29.         sanitizedStr = Replace(sanitizedStr, ")", ")")
  30.  
  31.         Return sanitizedStr
  32.     End Function

Any ideas on how to fix the errors?

Last edited by koncept; 09-10-07 at 01:15 PM. Reason: highlight code type
Reply With Quote
  #2 (permalink)  
Old 09-10-07, 01:14 PM
koncept
Guest
 
Posts: n/a
if this is just a functions class then you dont need the inherits. below is a snipet of one of mine

vbnet Code:
  1. Public Class SharedFunction
  2.     Shared Function SanitizeSQL(ByVal strInput As String) As String
  3.         Return strInput.Replace("'", "''").Replace("--", "-")
  4.     End Function
  5. end class
Reply With Quote
  #3 (permalink)  
Old 09-14-07, 08:22 PM
FreelanceMan FreelanceMan is offline
Newbie Coder
 
Join Date: Sep 2007
Location: Atlanta, GA
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
You're using the wrong HtmlEncode method. You want to use HttpUtility.HtmlEncode instead, because that's the static/shared version of the routine. Then you can pull out all the extra Imports that are messing with your shared function.
__________________
FreelanceLocalTech.com - Free Directory of Freelance Consultants - Are You In It?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
conceptual problem: abstract class, interface or class UnrealEd Everything Java 2 05-12-07 07:30 AM
I need to pass this class Please Help! Negative6 Everything Java 1 05-03-07 06:55 AM
Dif between static & instance method (I forgot)??PLEEESE! smartweezie Windows .NET Programming 1 09-18-05 03:54 PM


All times are GMT -5. The time now is 02:35 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.