How to popup a warning?

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?
 
D

David Young

Look at the Page.RegisterClientScriptBlock() method. This and javascript
should suit you well. The rest is a matter of logic and timing.

Dave
 
K

Kevin Spencer

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.
 
Q

Q. John Chen

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
 
S

Steve C. Orr [MVP, MCSD]

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top