FormView onClientclick postback issue

Last post 03-27-2008 11:01 AM by fimine. 2 replies.

Sort Posts:

  • FormView onClientclick postback issue

    03-27-2008, 10:51 AM
    • Loading...
    • KBShah
    • Joined on 01-30-2008, 3:15 PM
    • Posts 60
    I have a Formview1 which displays data from a table. On cllick "Delete", the user needs to confirm deletion of the record - this works fine. After deletion is complete, I want to display a message "Delete action completed" and finally take the user back to the default page. With the code below I am able to get the delete confirm and take teh user back to the default page, but not able to display the message "Delete action completed". Please help!  

    </ItemTemplate>

    <asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete"

    Text="Delete" Font-Bold="True" Font-Size="Medium" BorderStyle="ridge" BorderColor="DarkBlue"

    BorderWidth="2" ForeColor="DarkSlateBlue" Font-Underline="false"

    OnClientClick ="if(!confirm('Are you certain you want to Delete this record?'))return false;"></asp:LinkButton>

    Protected Sub FormView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewCommandEventArgs) Handles FormView1.ItemCommand

    ' this executes before formview_updating

    If e.CommandName.Equals("Delete") Then

    Page.ClientScript.RegisterStartupScript(Me.GetType(), "Myscript", "javascript:alert('Your record deleted')", True)

    ViewState("DeleteOK") = True

    End If

    End Sub

    Protected Sub FormView1_ItemDeleted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewDeletedEventArgs) Handles FormView1.ItemDeleted

    Try

    Page.ClientScript.RegisterStartupScript(Me.GetType(), "Myscript", "javascript:alert('DHCP database updated with reservation information')", True)

    Catch ex As Exception

    Finally

    Response.Redirect("default.aspx")

    End Try

    End Sub

     

  • Re: FormView onClientclick postback issue

    03-27-2008, 11:01 AM

    when you are  redirecting to default.aspx page, give a querystring to it.

    in default.aspx, page load event, check if there is query string or not, if there is querystring, then give the message you want to give. 

  • Re: FormView onClientclick postback issue

    03-27-2008, 11:01 AM
    Answer
    • Loading...
    • fimine
    • Joined on 01-17-2008, 9:01 AM
    • Montreal QC Canada
    • Posts 215

    Either this Page.ClientScript.RegisterStartupScript(Me.GetType(), "Myscript", "javascript:alert('Your record deleted')", True) has to go in your Default.aspx page and execute based on certain flag because the server forces client browser to redirect and thus all scripts registered with the current page will not run.

    OR:

    Keep your script where it is, but instead of having only alert calll a function:

    function deleted()
    {

         alert('Your record deleted')
        window.location = "Default.aspx"

    and get rid of the server-side redirect.  

     in this case your script will execute on the current page, display the message and redirect.

     


    _____________
    Don't forget to mark this post as "Answer" if it indeed answered.
Page 1 of 1 (3 items)