首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PageMethods不工作

PageMethods不工作
EN

Stack Overflow用户
提问于 2015-10-23 09:20:02
回答 1查看 78关注 0票数 0

我正在尝试学习如何在VB.NET中使用PageMethods,但我遇到了一些问题。由于某些原因,我无法让PageMethods调用的方法运行。

下面是javascript函数:

代码语言:javascript
复制
<script type="text/javascript">
    function AddHouse() {
        var address = document.getElementById("addrTxt").valueOf;
        var city = document.getElementById("cityTxt").valueOf;
        var state = document.getElementById("stateTxt").valueOf;
        var zip = parseInt(document.getElementById("zipTxt").valueOf);
        var firstName = document.getElementById("rFirstName").valueOf;
        var lastName = document.getElementById("rLastName").valueOf;
        var rent = parseInt(document.getElementById("rentAmt").valueOf);
        PageMethods.InsertHouse(address, city, state, zip, firstName, lastName, rent);
    }
</script>

下面是VB.NET代码:

代码语言:javascript
复制
Public Class _Default
Inherits Page

Private Shared dbConnection As String
Private file As String = "C:\\Projects\\HousingInfo\\HousingInfo\\bin\\housingInfo.db3"

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    dbConnection = String.Format("Data Source={0}", file)
    CreateTables()
End Sub

Private Sub CreateTables()
    Dim connection = New SQLiteConnection(dbConnection)
    If Not My.Computer.FileSystem.FileExists("C:\\Projects\\HousingInfo\\HousingInfo\\bin\\housingInfo.db3") Then
        SQLiteConnection.CreateFile("C:\\Projects\\HousingInfo\\HousingInfo\\bin\\housingInfo.db3")
    End If
    Using Query As New SQLiteCommand()
        connection.ConnectionString = dbConnection
        connection.Open()
        With Query
            .Connection = connection
            .CommandText = "CREATE TABLE IF NOT EXISTS houses(id INTEGER PRIMARY KEY AUTOINCREMENT, address TEXT, city TEXT, state TEXT,
                zipCode INTEGER, rent INTEGER, rFirstName TEXT, rLastName TEXT)"
        End With
        Query.ExecuteNonQuery()
        connection.Close()
    End Using
End Sub

<Services.WebMethod()>
Public Shared Sub InsertHouse(ByVal addr As String, ByVal city As String, ByVal state As String, ByVal zip As Integer, ByVal firstName As String,
                              ByVal lastName As String, ByVal rent As Integer)
    Dim connection = New SQLiteConnection(dbConnection)
    Using Query As New SQLiteCommand()
        connection.ConnectionString = dbConnection
        connection.Open()
        With Query
            .Connection = connection
            .CommandText = String.Format("INSERT INTO houses(address, city, state, zipCode, rent, rFirstName, rLastName) VALUES ('{0}', '{1}', '{2}', {3}, {4}, '{5}', '{6}'",
                                         addr, city, state, zip, firstName, lastName, rent)
        End With
        Query.ExecuteNonQuery()
        connection.Close()
    End Using
End Sub
End Class
EN

回答 1

Stack Overflow用户

发布于 2015-10-23 19:53:16

您使用了错误的属性来获取控件的值,请将'valueOf‘重命名为' value’,如下所示:

对所有其他出现的“valueOf”执行此操作

代码语言:javascript
复制
var address = document.getElementById("addrTxt").value;
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33293395

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档