Click here to Skip to main content
15,885,842 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
OnClientClick = "if (!confirm('Are you sure you want to delete this record?')) return;";

how can handle yes or no in case of message box
Posted
Updated 31-May-11 2:02am
v2
Comments
BobJanova 31-May-11 9:19am    
WinForms or ASPX?
Sergey Alexandrovich Kryukov 31-May-11 15:44pm    
Of WPF?
--SA

Hi heskapil,

I think you want to do something like that :

DialogResult result = MessageBox.Show("Are you sure you want to delete this record?", "Message", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{

}
else
    return;


I hope this help,
:)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-May-11 15:44pm    
Correct for Forms and WPF, a 5.
--SA
solution is simple...

VB
<asp:Button ID="DeleteButton" runat="server" OnClientClick="return confirm('Are you sure you want to delete this ?');" Font-Bold="True" Font-Size="Large" ForeColor="Blue"
        OnClick="DeleteButton_Click" Text="Delete" ToolTip="Click here to Delete this....."
        ValidationGroup="MyPersonal" Width="98px" />


and in DeleteButton_Click event write your deleting code in C#..


i.e.,

protected void DeleteButton_Click(object sender,eventargs e)
{
write your deleting code here
}

it will definitely work..

if the user clicks ok then the delete action will be done

if he clicks cancel nothing will be done...

try this...
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 31-May-11 15:45pm    
For APS.NET? But how do you know it's not WPF or Forms?
--SA
Hemant__Sharma 1-Jun-11 1:20am    
My 5. it's asp.net becaue OnClientClick is a property for ASP.NET Button server control and confirm is a javascript function.
Well caught.
karan joshua 1-Jun-11 6:38am    
yes well said by Hemant-sharma....
You're setting an event handler to acutal code? I don't think you can do that. It has to be a method (delegate) and you put the code into that method.
 
Share this answer
 
Comments
Hemant__Sharma 1-Jun-11 1:30am    
It's not event handler assignment, it's assigning value to a property.

Although the quesiton is not well formed but looking at the code it is confirmed it's in ASP.NET. because he is using i.e. OnClientClick (aps.net button server control's property) and confirm (javascript function for popup)
One can achieve it - having Yes/No instead of Ok/Cancel using vbScripts.

Please find the link below that has all the options and will help you out:
http://www.perlscriptsjavascripts.com/js/alertboxes.html[^]

This link would help: How to: Set the DefaultClientScript Property of a Web Page[^]

This link has a ample: here[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900