Question

I have a web form which when loading the form (on Page_Load), the text value of a textbox is prefilled with a value from a database. What I want is the ability for the user to change the value of this textbox, and then submit the form which sends an email with the value of this textbox in the body. However, when receiving the test email, the value that comes over is the original value that was loaded into the textbox on Page_Load, not the new value the user inputs. How do I make it so it uses the new value entered?

Sample code:

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
Was it helpful?

Solution

You need to use 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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top