我可以让我的函数在一页上运行,但是当我想从 App_Code 文件夹中调用该函数时,我在“CreateSentence”部分收到一个错误,说它引用了一个非共享成员。
如果有人有一个简单的共享函数示例(该函数位于 App_Code 文件夹中,而不是在同一页面上)或者可以指出错误,我会非常感激。
页数 - 3
1 - 默认.aspx
<asp:Button ID="Button1" runat="server" Text="Create Sentence" />
<asp:TextBox ID="word" runat="server"></asp:TextBox>
<asp:Label ID="sentence" runat="server" Text="Label"></asp:Label>
2 - 默认.aspx.vb
Imports Functions
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As System.EventArgs) Handles Button1.Click
sentence.Text = CreateSentence(word.Text)
End Sub
End Class
3 - App_code/Class1.vb
Imports Microsoft.VisualBasic
Public Class Functions
Function CreateSentence(ByVal word As String) As String
Dim Sentence As String = "The world you have is: " & word & "."
Return Sentence
End Function
End Class