0

I am a new developer of asp.net, now I have a problem on the issue of how to call java script function in asp.net. (I am lack of java-script)

I have a java-script code that will show the confirm modal popup like this

$('#modals-bootbox-confirm').click(function()
{
    bootbox.confirm("Are you sure?", function(result) 
    {
        $.gritter.add({
            title: 'Callback!',
            text: "BootBox Confirm Callback with result: " + result
        });
    });
});

I have known that this script binds to item with id "modals-bootbox-confirm" like

<input type="button" id="modals-bootbox-confirm" name="Hello"/>

but in asp the button will be initial with type = "submit" it cannot call this because after click the button it will postback all the time so how to use this script in asp.net

I have tried to change the id in the script to the asp's id but it does not work. How do I get the result from this modal control? Please help.

I know that asp has onClientClick but how to apply this script to it?

justin.m.chase
  • 13,061
  • 8
  • 52
  • 100
user3578971
  • 41
  • 1
  • 4

3 Answers3

0

its easy man,

Just do this

<asp:Button Id="aa" runat="server" onClientClick="function1();"/>

//and it Javascript turn it into function:

<script>

    function1()

    {
    bootbox.confirm("Are you sure?", function(result) 
        {
            $.gritter.add({
                title: 'Callback!',
                text: "BootBox Confirm Callback with result: "+ result
            });
        });


    }

    </script>
Adam
  • 3,815
  • 29
  • 24
  • Thank you. but it can not. But if it is the simple javascript like function script2() {return confirm('Hello!');} it can. – user3578971 Aug 21 '14 at 16:54
0

This is how to use OnClientClick:

<asp:Button OnClientClick="doSomething()" runat="server" />

Source: http://www.w3schools.com/aspnet/prop_webcontrol_button_onclientclick.asp

user145400
  • 1,076
  • 1
  • 12
  • 27
0

Very Short and Simple:

<asp:Button ID="Button1" runat="server" OnClientClick='return confirm("Are You Sure?")' />
user3786581
  • 401
  • 5
  • 13