开发者

form_load issue with updating details using session variables and textboxes

I'm trying to allow users to update their details after logging in on an asp site using vb. Textboxes are populated with user details using session variables in the form_load. The textboxes should be editable but for some reason are not registering the changes when the submit button is clicked.

There is a similar question with the same issue Database not updating after UPDATE SQL statement in ASP.net that was never answered.

Please can someone advise

Thanks in advance

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Txt_Fname.Text = Session("First_Name")
    Txt_LName.Text = Session("Last_Name")
    Txt_ContactNumber.Text = Session("Cell_Number")
    Txt_Email.Text = Session("Email_Address")
End Sub

Protected Sub Cmd_Submit_Click(ByVal sender As Object, B开发者_高级运维yVal e As System.EventArgs) Handles Cmd_Submit.Click



    Command.Connection = Connection
    Command.CommandText = "UPDATE dbo.User_Account Set First_Name = @First_Name, Last_Name = @Last_Name, Cell_Number = @Cell_Number, Email_Address = @Email_Address where Overall_ID = @Overall_ID"
    Command.Parameters.AddWithValue("@First_Name", Txt_Fname.Text)
    Command.Parameters.AddWithValue("@Last_Name", Txt_LName.Text)
    Command.Parameters.AddWithValue("@Cell_Number", Txt_ContactNumber.Text)
    Command.Parameters.AddWithValue("@Email_Address", Txt_Email.Text)
    Command.Parameters.AddWithValue("@Overall_ID", Session("ID"))

    Connection.Open()
    Command.ExecuteNonQuery()
    Connection.Close()

    Response.Redirect("MyAccount.aspx")
End Sub


Add if not page.ispostback before your code in page_load.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    If (Not Page.IsPostBack) then
        Txt_Fname.Text = Session("First_Name")
        Txt_LName.Text = Session("Last_Name")
        Txt_ContactNumber.Text = Session("Cell_Number")
        Txt_Email.Text = Session("Email_Address")
   End If
End Sub
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜