Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to get the result of confirm message

Status
Not open for further replies.

MzKitty

Programmer
Oct 28, 2003
254
US
I'm using VS2008 and .net 3.5. I have a gridview with edit and delete enabled. I have a message that pops up on the delete click that asks the client if they really want to delete this record, but I can't find the syntax to retrieve the result of the confirm message. My code is listed below:

strMsg = "Are you sure you want to delete this?"
ScriptManager.RegisterStartupScript(UpdatePanel2, UpdatePanel2.GetType(), "clientScript", "confirm('" + strMsg + "')", True)

I have been surfing the net for two days to find an answer to this or to recode differently, but my problem is that most of the code examples out there are in C not vb. Can anyone point me to a website that I can find an answer to this or tell me how to get the result from the above code.

Thanks
Cathy
 
I'm not sure what you are trying to do in your code, but I think you have 2 choices, both using the ItemDataBound event of the grid:

1.) Find the Delete link using FindControl() and add the js call to it (see below)

2.) Use a template column to hold a the Update and Delete, links or Buttons and use FindControl to add the js:
Code:
'this example show using an image button in a template column
DirectCast(e.Item.FindControl("ibDelete"), ImageButton).Attributes.Add("onClick", "return confirm('Are you sure you want to delete this row?');")





 
JavaScript is run on the client machine. You won't have a standard event in your .cs/.vb to handle this.

The best thing you use the js for to abort the server call and assume if the server code gets hit that the user clicked "Ok".

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this [red]"there was an error crap"[/red]
 
I added a template field to the gridview and configured it for Delete and my message comes up fine, but it still deletes the record. Here's my code:

<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server" CausesValidation="False" CommandArgument='<%# Eval("PurchaseOrder") %>' CommandName="Delete" OnClientClick="return Confirm 'Are you sure you really want to Delete?'" Text="Delete">Delete </asp:LinkButton>
</ItemTemplate>
</asp:TemplateField

I don't know where to trap the cancel so I can keep the record from being deleted.
 
If your hard set on doing the validation server side, create a hidden control and populate it's value in Javascript inside the function that pops the alert.

Check that hidden field on the delete to see if you should continue or just return.

Lod

If [blue]you have problems[/blue], I want [green]source code[/green] AND [green]error messages[/green], none of this "[red]there was an error[/red]" [black]crap[/black]
 
I've had weird issues with OnClientClick. Try adding the "onclick" js event as I show in the code above. Do that in the itemdatabound event of the grid.
 
thanks for the help. I've stewed over this for 4 days and am tabling it for now. I took the delete off of the gridview for now.
Thanks all.

Cathy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top