开发者

Calling javascript function in asp.net

开发者 https://www.devze.com 2022-12-22 04:27 出处:网络
Ok so this is a snippet of my aspx file, I am trying to call a \"hello world\" function from the \'test.js\' file. This is obviously not working, could someone please recommend me a good way of doing

Ok so this is a snippet of my aspx file, I am trying to call a "hello world" function from the 'test.js' file. This is obviously not working, could someone please recommend me a good way of doing it?

<asp:ScriptManager ID="ScriptManager1" runat="server">
    <Scripts>
        <asp:ScriptReference Path="\App_JavaScript\test.js" />
    </Scripts>
</asp:ScriptManager>
<asp:Button ID="timebutton" runat="server" Text="clickme" OnClick="javascript:getData();" /><br开发者_高级运维 />


OnClientClick

<asp:Button ID="timebutton" runat="server" Text="clickme" OnClientClick="javascript:getData();" />


Use jQuery to assign the function to the click event of the button.

    <script type="text/javascript" src="\App_JavaScript\test.js"></script>
    <script type="text/javascript" src="jQuery.js"></script>

    <script>

    $(document).ready(function(){
        $('#timeButton').click(getData);
        //Use below instead if you are using Master Pages
        //$('#<%= timeButton.ClientID %>').click(getData);
    });

    </script>

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


If you need a postback to occur you can also use ScriptManager.RegisterClientScriptBlock

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号