如何在提交表单asp.net时用新值覆盖预填充的文本框值

时间:2014-03-03 21:13:54

标签: asp.net vb.net forms postback

我有一个Web表单,在加载表单时(在Page_Load上),文本框的文本值预填充了数据库中的值。我想要的是用户能够更改此文本框的值,然后提交表单,该表单在正文中发送带有此文本框值的电子邮件。但是,在收到测试电子邮件时,遇到的值是加载到Page_Load上的文本框中的原始值,而不是用户输入的新值。如何使用输入的新值?

示例代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     txtEmail.Text = 'Email from db here'
End Sub

Protected Sub btnSubmitEmail_Click(sender As Object, e As EventArgs) Handles btnSubmitEmail.Click
     Dim emailAddress As String = txtEmail.Text
     SendMail(subject, "Email: " + emailAddress, fromAddress, toAddress)
End Sub

1 个答案:

答案 0 :(得分:1)

您需要使用 IsPostBack

Protected Sub Page_Load(sender As Object, e As EventArgs)
   If Not IsPostBack Then
      txtEmail.Text = 'Email from db here'
   End If
End Sub