You should add OnClientClick="return confirm('Are you sure you would like to import this file?');" as an attribute to your Button, and remove the if(confirm from the code-behind. Then if they confirm it will return true and the code-behind function will
execute, if they click no, then false is returned and the code-behind OnClick is never executed
I don't understand why after you help someone, they don't mark your post as the answer. What's up with that???
Marked as answer by dvongrad on Oct 23, 2012 03:32 PM
dvongrad
Member
16 Points
74 Posts
Javascript from ASP.NET C#
Oct 22, 2012 10:28 PM|LINK
I would like to do something like the following:
_btnImport.Click += new EventHandler(this._btnImport_Click);
private void _btnImport_Click(object sender, EventArgs e)
{
if (ValidFile()
if (confirm('Are you sure you would like to import this file?') // this is a Javascript call
ImportFile();
}
I'm sure this is possible to do but I'm at a loss. Any suggestions or links to other threads would be greatly appreciated. TIA
javedwahid
Participant
1687 Points
471 Posts
Re: Javascript from ASP.NET C#
Oct 22, 2012 10:52 PM|LINK
You should add OnClientClick="return confirm('Are you sure you would like to import this file?');" as an attribute to your Button, and remove the if(confirm from the code-behind. Then if they confirm it will return true and the code-behind function will execute, if they click no, then false is returned and the code-behind OnClick is never executed
arunoyour
Participant
1115 Points
264 Posts
Re: Javascript from ASP.NET C#
Oct 23, 2012 04:06 AM|LINK
use have to use javascript confirm dialog
sample code : http://www.w3schools.com/js/tryit.asp?filename=tryjs_confirm
Visit :: www.simplyasp.blogspot.com
Stay tune...Keep alive
ramiramilu
All-Star
97923 Points
14516 Posts
Re: Javascript from ASP.NET C#
Oct 23, 2012 07:07 AM|LINK
one other way is to have Ajax ConfirmButton Extender - http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/ConfirmButton/ConfirmButton.aspx
Thanks,
JumpStart
dvongrad
Member
16 Points
74 Posts
Re: Javascript from ASP.NET C#
Oct 23, 2012 03:32 PM|LINK
I knew it had to be something simple. Thanks.