Вызов JavaScript из Asp.Net CodeBehind (не функция) - PullRequest
1 голос
/ 20 ноября 2011

Мне нужно знать, как я могу вызвать приведенный ниже Javascript с событием нажатия кнопки в Asp.Net

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

Это моя обычная кнопка Asp.Net

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

1 Ответ

2 голосов
/ 20 ноября 2011

Оберните код внутри функции и вызовите функцию по событию нажатия кнопки клиентом.

<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();" />
...