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

    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.

    Blog :

  • #761830

    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">
    <script type="text/javascript" src="Test.js"></script>
    <form id="form1" runat="server">
    <asp:Button ID="btsubmit" runat="server" Text="Click" OnClientClick="NewPage();" />

    Name : Dotnet Developer-2015
    Email Id :

    '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 :

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

    Test.js contains this function :

    function NewPage() {
    // Your code goes here

    Hope this will help you.

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

  • Sign In to post your comments