A new record inserted into DB on each refresh.

Posted on 2006-06-06
Last Modified: 2006-11-18
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
            lReturn = pi_obj_Message.PostMessage(Session(Session_str_UserName), txthTo.Value, txtSubject.Text, Server.HtmlEncode(fckEditor.Value))
        Catch ex As Exception
            Exit Sub
        End Try
        lblMsg.Text = "Message sent successfully"
        lblMsg.Visible = True

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)
        objTransaction = objConnection.BeginTransaction()
        idbparameter(0) = GlobalData.DataHelper.GetParameter("@sender_id", DbType.String, 20, ParameterDirection.Input)
        idbparameter(0).Value = prm_Sender_ID

         .. other parameters..

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

        Catch ex As Exception
            Return False
        End Try
        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.

Question by:asifthakur
    1 Comment
    LVL 44

    Accepted Solution

    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

    Featured Post

    Enabling OSINT in Activity Based Intelligence

    Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

    Join & Write a Comment

    Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    This video discusses moving either the default database or any database to a new volume.

    729 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now