VB.NET文本框已更改但仍保留初始值

时间:2010-04-05 11:58:36

标签: asp.net vb.net user-controls textbox

我以前从未遇到过这个问题:

我有一系列文本框。这些框的文本在页面加载时设置。然后我有一个提交按钮,它调用一个子来用文本框中的新值(文本)更新表。问题是它保持原始文本不是文本框中当前的文本。有没有人遇到过这个?或者知道如何绕过它?

以下是我的提交按钮事件中的代码:

 Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSubmit.Click

    Dim Emails As Integer = txtEmails.Text
    Dim Calls As Integer = txtCalls.Text
    Dim Contacts As Integer = txtContacts.Text
    Dim Tasks As Integer = txtTasks.Text
    Dim Meetings As Integer = txtMeetings.Text
    Dim Proposals As Integer = txtProposals.Text
    Dim Points As Integer = txtPoint.Text

    Dim dt As New DataTable()
    Try
        connection.Open()

        Dim sqlCmd As New SqlCommand("UPDATE tblActivityParameters SET Emails = " & Emails & ", Calls = " & Calls & ", Contacts=" & Contacts & ", Tasks =" & Tasks & ", Meetings=" & Meetings & ", Proposals=" & Proposals & ",Points =" & Points, connection)

        Dim sqlDa As New SqlDataAdapter(sqlCmd)

        sqlDa.Fill(dt)
        lblError.Visible = True
        lblError.Text = "Parameters successfully updated"
    Catch SQLExp As SqlException
        lblError.Visible = True
        lblError.Text = "SQL Error: " + SQLExp.Message.ToString()
    Finally
        connection.Close()
    End Try
    GetParameters()
End Sub

干杯,

Jonesy

1 个答案:

答案 0 :(得分:2)

请检查您是否确定已在页面加载中检查过IspostBack。

if not(Me.IsPostBack) then

'fetch the values for initial load

end if

如果语法错误,我很抱歉,因为我是C#家伙。

HTH