Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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 ?

  1. Which code I need to put for confirm ?
  2. How can I execute it on Button Click ?

thanks

share|improve this question
1  
that's not alert, that's confirm – karaxuna Feb 28 at 12:54
which code should I need to add for that ? – ashuthinks Feb 28 at 12:57
confirm('this is a yes no question') and it returns boolean value – karaxuna Feb 28 at 12:58

3 Answers

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>
share|improve this answer
<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>
share|improve this answer

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.

share|improve this answer
not working for me :( in my logic i'm basically tried to work on javascript closure concept nothing else. – ashuthinks Feb 28 at 12:57
@ashuthinks When I say, your logic, I mean your steps you like to follow. Anyway, check for other javascript errors. This is the way – Aristos Feb 28 at 13:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.