views:

314

answers:

1

Hi Folks,

I've never come across this before:

I have a series of text boxes. The text of these boxes get set on page load. then I have a submit button that calls a sub to update the table with the new values (text) in the text box. The problem is it is keeping the original text not the text that is CURRENTLY in the textbox. Anyone come across this before? Or know how to get round it?

Here is the code from my submit button event:

 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

Cheers,

Jonesy

+1  A: 

Please check if you have made sure you have checked for IspostBack on the pageload.

if not(Me.IsPostBack) then

'fetch the values for initial load

end if

Sorry if the syntax is wrong since I am a C# guy.

HTH

Raja
thats just the ticket! thanks. I did: If isPostBack = False ThenAnd it worked a treat! Cheers--Jonesy
iamjonesy
Hi again got another problem that stems from the above. I have another page that has the same problem but its a bit different. this is my page load: 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 Sub When I postback from clicking the submit button I DON'T want to do the textbox1 if statement. Is there a way I can say if button1 caused postback do this.. else do this...?
iamjonesy