Link to home
Start Free TrialLog in
Avatar of asifthakur
asifthakur

asked on

A new record inserted into DB on each refresh.

This is the click functionality in the code behind on the send button that submits the form.

Private Sub ibtnfrmSend_Click(ByVal sender As System.Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ibtnfrmSend.Click

        Dim lReturn As Boolean
        pi_obj_Message = New Trade_BL.Message
        Try
            lReturn = pi_obj_Message.PostMessage(Session(Session_str_UserName), txthTo.Value, txtSubject.Text, Server.HtmlEncode(fckEditor.Value))
        Catch ex As Exception
            Trace.Write(ex.Message)
            Exit Sub
        End Try
        lblMsg.Text = "Message sent successfully"
        lblMsg.Visible = True
        ClearForm()

End Sub

this is the implementation in the business logic.

Public Function PostMessage(ByVal prm_Sender_ID As String, ByVal prm_To_ID As String, ByVal prm_Subject As String, ByVal prm_Content As String) As Boolean
        Dim idbparameter(4) As IDataParameter
        Dim idb_Member_Cat_parameter(1) As IDataParameter
        Dim dt_row As DataRow
        Dim objTransaction As IDbTransaction
        Dim objConnection As IDbConnection

        objConnection = pi_objHelper.GetConnection(GlobalData.ConnectionString)
        objConnection.Open()
        objTransaction = objConnection.BeginTransaction()
        idbparameter(0) = GlobalData.DataHelper.GetParameter("@sender_id", DbType.String, 20, ParameterDirection.Input)
        idbparameter(0).Value = prm_Sender_ID

         .. other parameters..

        Try
            pi_objHelper.ExecuteNonQuery(objTransaction, CommandType.StoredProcedure, "USP_INSERT_MESSAGE", idbparameter)

        Catch ex As Exception
            objTransaction.Rollback()
            objConnection.Close()
            Trace.Write(ex.Message)
            Return False
        End Try
        objTransaction.Commit()
        objConnection.Close()
        Return True

    End Function

when i insert the first record, the form is hidden and the grid on the same page is displayed.. but does not show the new posting. lets assume .. an member sends an email to himself... once you submit the form the record is inserted.. but the grid that pulls data in the page_load of the same page.. does not show it.. if i try to reload the page.. to force datagrid to pull data.. the entire form submission takes place again.. and a new record is inserted into the db. it keeps happening till the time you goto other page and then come back.

Regards,
ASKER CERTIFIED SOLUTION
Avatar of TimCottee
TimCottee
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial