开发者

Visual Studio Finding out RootSpaceName of a Class in a subfolder

I have a visual studio website solution with the following structure

A page called Default.aspx in the root folder

and a folder called App_Code in which I have added a class called Test2.vb

I am wondering how I can call the methods from my class Tes2.vb in Default.aspx.vb

I have tried

Dim test1 As New Test2 (Which didnt work) Dim test3 As New United_Site.Test2 (Adding site name also didnt work)

My Code for Test2 Class

Public Class Test2
Public Function ReplaceXSS(ByVal InputString As String) As String
    InputString = InputString.Replace("<script>", "")
    InputString = HttpUtility.HtmlEncode(InputString)
    InputString = InputString.Replace("</script>", "")
    InputString = InputString.Replace("&", "&#38;")
    InputString = InputString.Replace("<", "&#60;")
    InputString = InputString.Replace(">", "&#62;")
    InputString = InputString.Replace("%", "&#37;")
    InputString = InputString.Replace("|", "&#124;")
    InputString = InputString.Replace("$", "&#36;")
    InputString = InputString.Replace("'", "&#39;")
    InputString = InputString.Replace("""", "&#92;")

    ReplaceXSS = InputString
End Function

End Class

and my code for default.aspx

Partial Public Class _Default
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim test As New Class1 ' Make an object of that class
    Dim test2 As New Spurs ' Make an object of that class
    Dim test3 As New Test2 <--- Error


End Sub

End Class

Ok one more thing I noticed is a follows, if I create a brand new folder and a new class I c开发者_开发百科an call it no problems i.e. Dim test3 As New Test5 and test test5 class is in a folder called "Classes". The issue seems to be my original folder classes called App_Code which is a .NET folder I believe and is grey compared to other folders, I also copied this folder in from a different site.


Probably have to do with the namespace declarations.

Check the namespace on the test2.vb

if you see something like

namespace test2

then go to the files that you like to use the functions of the test2.vb and add on the first lines

Imports test2

Also, visualstudio 2010 can help you add automatically this namespace. In the line that you see the error if you move the mouse over you see a red sign that suggest you what to do, for example can suggest to add the Imports test2

Second possible reason

You have an error on your class and they are not have been compiled, so your program can not find them. Check for errors on test2.vb. You can also make rightclick on the solution and select to compile your site to see the messages of errors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜