i have used
<asp:CommandField ShowEditButton="true" ButtonType="Link" EditText="Edit"
ShowHeader="true" HeaderText="Edit"
HeaderStyle-Font-Bold="true" />
<asp:CommandField> in my gridview.
Response.Write("<script>confirm('Are you sure');</script>");
if("OK")
{
}
else
{
}
how to take the value if ok is cliked or not
i need to show the confirm box when this edit is cliked,using c# and not java script. how to trigger that conf开发者_StackOverflow社区irm box with this code.
pls help
There are a couple of options, if you are using AJAX then you can use the ModalDialogExtender to create a kind of 'popup' - say an ASP.NET control that appears over the top of the page and prompts for confirmation.
If not, the best way to interact with the user is still JavaScript, but from the sounds of it you want to cause the popup to occur from your C# code, based on some more logic for example. One option would be to set the 'onclick' attribute of a button, the value of which is interpreted as JavaScript and executed when the button is clicked (and it can abort the button click event if the JavaScript returns a value of 0).
This may come in useful, though it is in the VB.NET language:
http://authors.aspalliance.com/aldotnet/examples/cd.aspx
And here's a good article on the topic from Microsoft, in C#:
http://www.asp.net/data-access/tutorials/adding-client-side-confirmation-when-deleting-cs
They apply to deletion, which is the more common reason to add a confirmation box, but the same technique can be used for 'edit' operations.
精彩评论