如何通过 aspx 页调用.vb文件中的函数



我已经创建了网络表单aspx文件,我有一个按钮来生成pdf然后上传到我的表单。当我点击提交按钮时,需要调用 vb 文件中的函数,例如用于 DocuSign 的 CreateEnvelpoeAPI。无论如何,如何通过aspx页面调用函数?

//form.aspx.vb
Protected Sub btSubmit_Click(sender As Object, e As EventArgs) Handles btSubmit.Click
    Response.Redirect("CreateEnvelopeAPI.vb") // I expecte to call function n in here.
End Sub
// CreateEnvelopeAPI.vb
Public Class CreateEnvelopeAPI
Public Function Init() As String
    Dim username As String = ""
    Dim password As String = ""
    Dim integratorKey As String = ""
    ' initialize client for desired environment (for production change to www)
    Dim apiClient As New ApiClient("https://demo.docusign.net/restapi")
    Configuration.[Default].ApiClient = apiClient
    ' configure 'X-DocuSign-Authentication' header
    Dim authHeader As String = (Convert.ToString((Convert.ToString((Convert.ToString("{""Username"":""") & username) + """, ""Password"":""") & password) + """, ""IntegratorKey"":""") & integratorKey) + """}"
    Configuration.[Default].AddDefaultHeader("X-DocuSign-Authentication", authHeader)
    ' we will retrieve this from the login API call
    Dim accountId As String = Nothing
    '''//////////////////////////////////////////////////////////////
    ' STEP 1: LOGIN API        
    '''//////////////////////////////////////////////////////////////
    ' login call is available in the authentication api 
    Dim authApi As New AuthenticationApi()
    Dim loginInfo As LoginInformation = authApi.Login()
    ' parse the first account ID that is returned (user might belong to multiple accounts)
    accountId = loginInfo.LoginAccounts(0).AccountId
    ' Update ApiClient with the new base url from login call
    apiClient = New ApiClient(loginInfo.LoginAccounts(0).BaseUrl)
    Return accountId
End Function
Public Sub CreateEnvelopeAPI()
    Dim accountId As String = Init()
    Dim fileBytes As Byte() = File.ReadAllBytes("Invoice.pdf")
    Dim envDef = New EnvelopeDefinition()
    envDef.EmailSubject = "[DocuSign C# SDK] - Custom Fields"
    envDef.Status = "sent"

    envDef.CustomFields = New CustomFields()
    Dim textCustomField = New TextCustomField()
    textCustomField.Name = "TransactionId"
    textCustomField.Value = "KTI456"
    Dim textCustomFields = New List(Of TextCustomField)()
    textCustomFields.Add(textCustomField)
    envDef.CustomFields.TextCustomFields = textCustomFields
    ' Add a recipient to sign the documeent
    Dim signer As New Signer()
    signer.Email = ""
    signer.Name = ""
    signer.RecipientId = "1"
    signer.Tabs = New Tabs()
    signer.Tabs.SignHereTabs = New List(Of SignHere)()
    Dim signHereTab = New SignHere()
    signHereTab.DocumentId = "1"
    signHereTab.PageNumber = "1"
    signHereTab.XPosition = "100"
    signHereTab.YPosition = "100"
    signer.Tabs.SignHereTabs.Add(signHereTab)
    envDef.Recipients = New Recipients()
    envDef.Recipients.Signers = New List(Of Signer)()
    envDef.Recipients.Signers.Add(signer)
    ' Add a document to the envelope
    Dim doc As New Document()
    doc.DocumentBase64 = System.Convert.ToBase64String(fileBytes)
    doc.Name = "Invoice.pdf"
    doc.DocumentId = "1"
    envDef.Documents = New List(Of Document)()
    envDef.Documents.Add(doc)

    Dim envelopesApi As New EnvelopesApi()
    Dim envelopeSummary As EnvelopeSummary = envelopesApi.CreateEnvelope(accountId, envDef)
    Console.WriteLine(envelopeSummary)
End Sub
End Class

您可以像调用 VB 中的任何其他函数一样调用函数。事实上,它处于 ASP.NET 页面的上下文中,对此没有任何区别。

Protected Sub btSubmit_Click(sender As Object, e As EventArgs) Handles btSubmit.Click
    Dim api = new CreateEnvelopeAPI() 'instantiate the class
    api.CreateEnvelopeAPI() 'call a function
End Sub

(注这是假设 CreateEnvelopeAPI.vb 文件是项目的一部分,并且该类位于同一命名空间中。如果不是上述任一情况,则只需包含该文件和/或添加 Imports 语句即可在 aspx 代码中包含命名空间。

P.S. Response.Redirect,如果你想将浏览器发送到另一个页面(即另一个HTTP URL(,而不是在你的代码中调用一个函数。

最新更新