[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 268
  • Last Modified:

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,
0
asifthakur
Asked:
asifthakur
1 Solution
 
TimCotteeCommented:
Hi asifthakur,

Ok, so the reason is that page_load is executed first then your button click event. You need to move the code that populates the grid out of page_load into a seperate sub (you may already have this of course) and call this after the ClearForm() call in the click event. This way your grid will get the latest data including the posted message.

From what you say, there is really no need to have the grid populating in page_load anyway because it is not displayed initially, only on the postback. Therefore as long as it is called at some point (i.e. in the click event) it will be fine.

Tim Cottee
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now