I'm working on asp 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
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
Share Improve this question edited Feb 28, 2013 at 12:58 Neo asked Feb 28, 2013 at 12:51 NeoNeo 16.2k66 gold badges237 silver badges427 bronze badges 3- 1 that's not alert, that's confirm – karaxuna Commented Feb 28, 2013 at 12:54
- which code should I need to add for that ? – Neo Commented Feb 28, 2013 at 12:57
- confirm('this is a yes no question') and it returns boolean value – karaxuna Commented Feb 28, 2013 at 12:58
4 Answers
Reset to default 4I 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>
<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>
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..
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.