You must Sign In to post a response.
  • Category: ASP.NET

    Call external javascript method on click of button

    I have search button in .aspx page.
    Also i have test.js [a separate js file] which has a function {NewPage()] which inturn calls an ajax method.

    Now how do i call this "NewPage()" method on search button click?
  • #761829
    Hi,

    You just include your javascript file in your page by this way you can call "NewPage()" function.


    <script src=".../test.js" language="javascript" type="text/javascript" />


    Hope this will helpful to you..

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #761830
    Hi

    You can create one external js file this
    file name should be test.js


    function NewPage() {
    alert('New Page show');
    return false;
    }


    How to call from aspx Page code this


    <head runat="server">
    <title></title>
    <script type="text/javascript" src="Test.js"></script>
    </head>
    <form id="form1" runat="server">
    <asp:Button ID="btsubmit" runat="server" Text="Click" OnClientClick="NewPage();" />
    </form>

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #761844
    If you include the file and the file contains the method in normal manner, you can call that method directly in the button click.

    If the file done in class manner, you have to create the instance and call the method

    By Nathan
    Direction is important than speed

  • #761946
    Hello Kumaresh,

    Refer the below code :

    <html>
    <head runat="server">
    <title>Sample</title>
    <script type="text/javascript" src="Test.js"></script>
    </head>
    <body>
    <form id="Form1" runat="server">
    <asp:Button ID="btnclick" runat="server" Text="Click Me!" OnClientClick="NewPage();" />
    </form>
    </body>
    </html>


    Test.js contains this function :

    function NewPage() {
    // Your code goes here
    }


    Hope this will help you.

    Regards,
    Nirav Lalan
    DNS Gold Member
    "Failure is the path of least persistence"


Sign In to post your comments