0

I have a repeater and in its ItemCommand code, I need to do a database check if some records deleted and if yes, ask if the user wants to continue. Something like this

    If e.CommandName="Clone" Then
            'Do the database check to see if records deleted and if yes
            'show a confirmation dialog and if user answers "yes" continue, if "no" stop
    End If

The command "Clone" is coming from a LinkButton. Also, I want to do this in ItemCommand instead of ItemCreated or DataBound because I do not want the check to be added for every record. It only executes when I click the Linkbutton

Is this possible? Thanks.

Lac Ho
  • 217
  • 4
  • 15

1 Answers1

0

You could do this a couple of ways.

One way would be to instead of doing a full post back when the link button is clicked make an ajax call to the server to see if the record is deleted. Then you could display the javascript confirmation dialog after the ajax request is complete. If the user answers 'yes' then you could make another ajax request or trigger a full postback via __doPostBack to a clone event handler with the appropriate arguments.

Here is a simple way to make an ajax call: Calling a webmethod with jquery in asp.net webforms

An alternative method would be to do the initial full post back to the server, do the database check, and then return some javascript to the client which would cause the confirmation messsage to display. Then you would handle the result of the confirmation via javascript and do an ajax/full post back as necessary to perform the clone.

gl

Community
  • 1
  • 1
Dana Benson
  • 966
  • 7
  • 16
  • I did try the second method but could not make the dialog appear. I tried something like this Dim t As Type = Me.[GetType]() Dim confirmMsg = "return confirm('Are you sure you want to continue?');" ScriptManager.RegisterStartupScript(Me.Page, t, "ConfirmScript", confirmMsg, True) It works if it's an alert but not confirmation – Lac Ho Mar 29 '12 at 23:43