【问题标题】:VB.NET textbox changed but still hold initial valueVB.NET 文本框已更改但仍保持初始值
【发布时间】:2010-04-05 11:58:35
【问题描述】:

我以前从未遇到过这种情况:

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

这是我提交按钮事件的代码:

 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

干杯,

琼斯

【问题讨论】:

  • 你有任何代码可以为你的提交按钮事件发布吗?
  • 我已经用提交按钮事件的代码编辑了我的帖子

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


【解决方案1】:

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

if not(Me.IsPostBack) then

'fetch the values for initial load

end if

对不起,如果我是 C# 人,语法错误。

HTH

【讨论】:

  • 这只是门票!谢谢。我做到了: If isPostBack = False Then 而且它奏效了!干杯——琼斯
  • 嗨又遇到了另一个源于上述问题的问题。我有另一个页面有同样的问题,但它有点不同。这是我的页面加载: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If IsPostBack = True Then If TextBox1.Text String.Empty Then CheckDate() End If End If End If End Sub当我从单击提交按钮回发时,我不想执行 textbox1 if 语句。有没有办法我可以说如果 button1 导致回发这样做.. 否则这样做...?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-10-09
  • 1970-01-01
相关资源
最近更新 更多