I'm working on asp.net and want to execute following javascript code. I'm using VS2010.
<title></title>
<script type="text/javascript">
function myClosure() {
var canyousee = "here I'm ";
return (function theClosure() {
return { canyouseeIt: canyousee ? "yes" : "no" };
});
}
var closure = myClosure();
closure().canyouseeIt;
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="myClosure();" />
</div>
How do i execute function myClosure() on button click so that It gives me confirm i.e popup for yes or no ?
- Which code I need to put for
confirm? - How can I execute it on
Button Click?
thanks
asked Feb 28, 2013 at 12:51
Neo
16.3k68 gold badges241 silver badges428 bronze badges
-
1that's not alert, that's confirmkaraxuna– karaxuna2013年02月28日 12:54:40 +00:00Commented Feb 28, 2013 at 12:54
-
which code should I need to add for that ?Neo– Neo2013年02月28日 12:57:52 +00:00Commented Feb 28, 2013 at 12:57
-
confirm('this is a yes no question') and it returns boolean valuekaraxuna– karaxuna2013年02月28日 12:58:36 +00:00Commented Feb 28, 2013 at 12:58
4 Answers 4
I hope this can be of some help. I must confess that what you want to achieve is not clear to me.
<title></title>
<script type="text/javascript">
myClosure=function() {
var canyousee = "here I'm ";
return (function () {
return { canyouseeIt: function(){return confirm (canyousee)}};
});
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="(myClosure())().canyouseeIt()" />
</div>
answered Feb 28, 2013 at 14:41
jbl
15.5k3 gold badges38 silver badges104 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
<html>
<head>
<script type="text/javascript">
function myClosure(){
var r=confirm("Press a button!")
if (r==true)
{
alert("You pressed OK!")
return true;
}
else
{
alert("You pressed Cancel!");
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="myClosure();" />
</div>
</body>
</html>
answered Feb 28, 2013 at 13:10
Ahmed Abdullah Saeed
7072 gold badges8 silver badges20 bronze badges
Comments
use
onclientclick="javascript:return YourFunction();"
<script>
function YourFunction() {
//Do your stuff
return true;
}
</script>
If you return true your asp.new onclick event will be called.. If you return false it wont be called..
answered Aug 17, 2014 at 5:16
Hirav Sampat
1961 silver badge11 bronze badges
Comments
as you call it, but prevent the post back by return false on
OnClientClick="myClosure();return false;"
I do not know nether understand the rest of your logic, but this is your issue right now.
answered Feb 28, 2013 at 12:54
Aristos
66.7k16 gold badges117 silver badges154 bronze badges
lang-js