locked
browsers back button re executes my details view ItemUpdatedCode/ItemInserted code RRS feed

  • Question

  • User-89664073 posted

    I have a details view inside a webform. If i Create a new record in the grid or update an existing record, it runs the code behind for the ItemInserting/ItemInserted, etc. However, if i click another link on my page and then hit the back button it re executes the ItemInserted code again. It does not re execute the ItemInserting, just the ItemInserted code.

    -- asp drop down

    <InsertItemTemplate>
    <asp:DropDownList
    ID="ddIIProcess"
    runat="server"
    DataSourceID="dsIIProcess"
    DataMember="DefaultView"
    DataTextField="process_name"
    DataValueField="process_id"
    AutoPostBack = "true"
    SelectedValue='<%# Bind("process_id")%>'>
    </asp:DropDownList>
    <asp:SqlDataSource
    ID="dsIIProcess"
    runat="server"
    ConnectionString="<%$ ConnectionStrings:ocd_stagingConnectionString %>"
    SelectCommand="select process_id, process_name from config.process (nolock) order by process_name">
    </asp:SqlDataSource>
    </InsertItemTemplate>

    -- add button

    Protected Sub btnAdd_Click(sender As Object, e As EventArgs) Handles btnAdd.Click
    dvConfigs.ChangeMode(DetailsViewMode.Insert)
    dvConfigs.AutoGenerateInsertButton = "True"
    btnAdd.Visible = "False"
    btnDelete.Visible = "False"
    gvConfigs.Enabled = "False"
    End Sub

    -- item inserted code / this runs again if i click back. I get the java script message again

     
        Private Sub dvConfigs_ItemInserted(sender As Object, e As System.Web.UI.WebControls.DetailsViewInsertedEventArgs) Handles dvConfigs.ItemInserted
     
            MesgBox("Configuration " + e.Values(0).ToString() + " has been added")
            gvConfigs.DataBind()
            dvConfigs.DataBind()
            For Each r As GridViewRow In gvConfigs.Rows
                If gvConfigs.DataKeys(r.RowIndex)(1) = e.Values(0) Then
                    gvConfigs.SelectedIndex = r.RowIndex
                    gvConfigs.DataBind()
                    dvConfigs.DataBind()
                    Exit For
                End If
            Next
        End Sub

    Tuesday, March 27, 2018 10:01 PM

All replies