using java script along with ASP.NET language C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 02Mack
    New Member
    • Feb 2012
    • 1

    using java script along with ASP.NET language C#

    I want to add .js file along with ASP.NET my code is:

    Code:
    Page.ClientScript.RegisterStartupScript(this.GetType(), "MyJavaScript",
                "JScript1.js",true);
    
    Button1.Attributes["onclick"] = "Alert()";
    My .js file is:
    Code:
    function Alert() 
    {
        alert('good morning');
    }
    I have add:
    Code:
    <head runat="server">
     <script language="javascript" src="JScript1.js" type="text/javascript"></script>
    </head>
    That code was showing error:
    JScript1.js is udefined

    please help me
    Last edited by Frinavale; Feb 27 '12, 09:17 PM. Reason: Added code tags. Please post code in code tags.
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Since you have already added the JavaScript to the header of the file, you do not need to use the Page.ClientScri pt.RegisterStar tupScript method.

    Actually, that doesn't explain the error.
    Do you have a file called "JScript1.j s" in the same director as the page that is trying to access it?

    I think your url to the JavaScript file is probably incorrect.

    -Frinny

    Comment

    Working...