我可以讓我的功能在一個頁面上工作,但是當我想從App_Code文件夾中調用該函數時,我在「CreateSentence」部分發現一個錯誤,指向一個非共享成員。公共課和App_Code
如果有人有一個簡單的共享函數示例(其中函數位於App_Code文件夾中,而不在同一頁上),或者可以指出錯誤,我會非常感激。
頁 - 3
1 - Default.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 - Default.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