Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I'm using bootstrap alert autocloseable msg. Code as follow

<div id="alertdiv" class="alert">
    <a class="close" data-dismiss="alert">×</a><span>' + message + '</span></div>

Asp.net Button click code

<div>
 <asp:Button ID="btnLogin" runat="server" Text="Login" CssClass="btn btn-block org" Style="margin-top: 0px" OnClick="btnLogin_Click" ValidationGroup="Login" OnClientClick="msg();" />
</div>

Javascript code as follow. Is javascript written is correct ? Please check it out!

<script type="text/javascript">

    $(document).ready(function () {
        function msg() {
            window.setTimeout(function () {
                $(".alert").fadeTo(1500, 0).slideUp(500, function () {
                    $(this).remove();
                });
            }, 5000);
        }
    });

</script>
share|improve this question
    
did you get an error? –  Dyrandz Famador Apr 1 at 2:25
    
No! , the script doesn't get fired@DyrandzFamador –  Rohan Apr 1 at 2:29
    
try the example below @Rohan. it's an example of calling the javascript from asp button –  Dyrandz Famador Apr 1 at 2:31
    
Ok,wait for a sec!@DyrandzFamador –  Rohan Apr 1 at 2:33
    
Compilation Error Msg : CS1002 ; expected at Sub btClick1(obj As Object, e As EventArgs) @Dyrandz –  Rohan Apr 1 at 2:46

3 Answers 3

up vote 1 down vote accepted

Follow this link

enter link description here

share|improve this answer
    
Your answers works thanks a lot!!! –  Rohan Apr 1 at 5:16
    
@Rohan u r welcm –  user2220144 Apr 1 at 5:18

I hope this can be of some help. I must confess that what you want to achieve is not clear to me.

<script type="text/javascript">
     myClosure=function() {
        var canyousee = "here I'm ";
        return (function () {
            return { canyouseeIt: function(){return confirm (canyousee)}};
        });
    }
</script>


<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="(myClosure())().canyouseeIt()" />
share|improve this answer
    
I want to achieve is the div tag , which is called through javascript with some time function in it, after some sec the div would fade out . This javascript is called through asp.net button click . @Shohel –  Rohan Apr 1 at 3:14
function msg() {
    window.setTimeout(function () {
        $(".alert").fadeTo(1500, 0).slideUp(500, function () {
            $(this).remove();
        });
    }, 5000);
}

You're declaring your function inside your ready. Declare it outside of it.

$(document).ready(...); basically says "when my document is finished rendering, run the code within." You don't want to do that, you just want to declare your function for use in your OnClientClick. If you move msg() out of the .ready(), it should work.

Also, ASP.NET controls render as regular html. I believe an <asp:button> renders as a regular button, if I'm not mistaken. You can use a delegated event handler like so:

$('#' + '<%= btnLogin.ClientID %>').on('click', function() {
    msg();
});
share|improve this answer
    
I cant understand the code $('#yourclientid').on('click', function(){ });. Would you please write in my code ? I'm an learner of asp & javascript .@Yatrix –  Rohan Apr 1 at 3:06
    
I tried your updated code , it doesn't display msg function @Yatrix –  Rohan Apr 1 at 3:19
    
@Rohan is it hitting the message function? Your comments above said msg() wasn't fire at all. –  Yatrix Apr 1 at 3:21
    
How to figure it out? Would you explain ! @Yatrix . Yes the msg() wasn't fired ! –  Rohan Apr 1 at 3:23
    
You have to learn how to debug JavaScript in the browser console. I can't explain that to you, that's something you have to learn to do. SO is here to help you answer certain questions, not teach you how to program. Just do some google searching and you should be able to learn everything you need to know for debugging .js. –  Yatrix Apr 1 at 3:24

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.