How to popup a warning?

  • Thread starter Thread starter Q. John Chen
  • Start date Start date
Q

Q. John Chen

I have a "Delete" button on WebForm, but I want to popup a warning
message with OK and Cancel in case user clicked the button by accident.
HOW?
 
Look at the Page.RegisterClientScriptBlock() method. This and javascript
should suit you well. The rest is a matter of logic and timing.

Dave
 
Example:

<script type="text/javascript"><!--
function IsAccident() {
return (confirm("Is this an accident?");
}
// --></script>

<form ... onsubmit="return IsAccident()">

Explanation:

When an HTML form is submitted, the "onsubmit" event handler gives a "last
chance" to cancel the submit. It can call a JavaScript function that returns
true or false. If the function returns true, the form is submitted. If not,
the form is not submitted.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
What You Seek Is What You Get.
 
Thanks both for the quick response. I may put the question too simple.
My web form contains.

1. A "Search" button that retrieve data and fills the TextBoxes,
DropdownLists, and a DataGrid on the form.

2. An "Update" button to save the changes to the TextBoxes and
DropdownLists.

3. The DataGrid contains a Button Column ("Remove") on every row to
delete the datarow and all the Children (via FK cascading).

What I wanted is to popup warning when user click "Update" or the
"Remove".

I guess that putting code onsubmit will popup the warning even click on
the "Search" button.

I am thinking of UpdateButton.Attributes.Add("onclick", "return
confirm('Is this an accident?"); But wil this prevent form be
submitted. Also if doing popup on individual buttons, what about the
"Remove" buttons in the grid?

Thanks

John



1. I want a warnt
 
Here's some server side code that uses javascript to display a confirmation
message.

myDeleteButton.Attributes.Add("onclick", _
"return confirm('Are you sure you want to delete?');")

In this example, the Delete button will post back only if the person
confirms they want to delete. Otherwise your server code is never called in
response to the button click.

Here's information about making this technique work with a datagrid:
http://www.dotnetjunkies.com/HowTo/1E7FEE4A-795C-4D33-A135-843EB07C94A8.dcik
 
Back
Top