最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jquery - How do I call javascript from asp.net button click? - Stack Overflow

programmeradmin1浏览0评论

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 ?

  1. Which code I need to put for confirm ?
  2. 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 ?

  1. Which code I need to put for confirm ?
  2. 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
Add a comment  | 

4 Answers 4

Reset to default 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>
<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.

发布评论

评论列表(0)

  1. 暂无评论