Click here to Skip to main content
15,908,175 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a syntax like this
onclick=\"if(confirm('Are you sure you want to delete?')) return DeleteNews(1); else return false;\"

DeleteNews is a function

function DeleteNews(id) {
}

i just want that if user confirm that and click or yes on alert which ask Are you sure to delete... return 1 to function DeleteNews or if user click on NO so its do nothing

in my syntax its not return na value
help me ......
Posted
Comments
ZurdoDev 14-Jul-13 8:15am    
Put a breakpoint and see what is happening. Just looking at it, it would appear that clicking No would return false and click Yes would return whatever DeleteNews returns. What does DeleteNews return?
Arbaz Ali 14-Jul-13 8:17am    
its return an int id
ZurdoDev 14-Jul-13 8:22am    
OK. Then you'll need to put a breakpoint and walk through your code and see what is happening.
OriginalGriff 14-Jul-13 8:18am    
Please don't post a new question to add information - use the "Improve Question" widget instead.
I have deleted the "spare" copy.
_Asif_ 14-Jul-13 10:09am    
I suggest to create a new function and put logic in that function. This would improve maintanability

Try this

C#
onclick="return AskConfirmation();"

Function AskConfirmation()
{
    var answer = confirm('Are you sure you want to delete?');
        if (answer==true){
            DeleteNews(1);
        } else {
            return false;
        }
    return false;
}
 
Share this answer
 
Try this. in your code behind
C#
btn.Attributes.Add("onClick","return alert('do you want to delete this record')");
 
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