1

I need to know how can I call the below Javascript with a button click event in Asp.Net

<script type='text/javascript'>
        $("#various3").fancybox({
            'width': '75%',
            'height': '75%',
            'autoScale': false,
            'transitionIn': 'none',
            'transitionOut': 'none',
            'type': 'iframe'
        });
</script>

This is my normal Asp.Net button

<asp:Button ID="Button1" runat="server" Text="Button" />

1 Answer 1

2

Wrap the code inside a function and call the function on client click event of the button.

<script type='text/javascript'>
   function createFancyBox() {
    $("#various3").fancybox({
        'width': '75%',
        'height': '75%',
        'autoScale': false,
        'transitionIn': 'none',
        'transitionOut': 'none',
        'type': 'iframe'
    });
    // include this line to stop the button to call the server side event
    return false;
  }
</script>

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="return createFancyBox();" />
Sign up to request clarification or add additional context in comments.

2 Comments

+1 but since the function will always return false and nothing ever will postback from the click of this button; i'd get rid of the asp:button control and just have a regular button element.
@Waqas-For button it dosen't work properly and If I use hyperlink it works well and what may be the reason for this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.