Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Call External Javascript File in aspx file

Call External Javascript File in aspx file

Scheduled Pinned Locked Moved ASP.NET
javascripthtmlregexhelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    anandhakrishnan
    wrote on last edited by
    #1

    Hi, I have written the javascript function in the External js file and named it as JScript.js. This file is in Javascripts folder which under the Project folder. The JScript.js file contains the following code. // JScript File function validateParameter() { var paramname=document.getElementById('<%=txtParam.ClientID %>'); var message; message=""; if(paramname.value=="") { message+="\n*Parameter Name is mandatory"; } else if(paramname.value!="") { var alphaExp = /^[a-zA-Z\s]+$/; if(!paramname.value.match(alphaExp)) { message+="\n*Only Alphabets are allowed for Parameter Name"; } } if(message!="") { alert(message); return false; } return true; } I have called the javascript file using the below html tag. I have called the javascript function for OnClientClick of a button. OnClientClick="javascript: return validateParameter();" But during the runtime the button click is not validating the controls. Please Help Me! Thanks.

    N A 2 Replies Last reply
    0
    • A anandhakrishnan

      Hi, I have written the javascript function in the External js file and named it as JScript.js. This file is in Javascripts folder which under the Project folder. The JScript.js file contains the following code. // JScript File function validateParameter() { var paramname=document.getElementById('<%=txtParam.ClientID %>'); var message; message=""; if(paramname.value=="") { message+="\n*Parameter Name is mandatory"; } else if(paramname.value!="") { var alphaExp = /^[a-zA-Z\s]+$/; if(!paramname.value.match(alphaExp)) { message+="\n*Only Alphabets are allowed for Parameter Name"; } } if(message!="") { alert(message); return false; } return true; } I have called the javascript file using the below html tag. I have called the javascript function for OnClientClick of a button. OnClientClick="javascript: return validateParameter();" But during the runtime the button click is not validating the controls. Please Help Me! Thanks.

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Best way is to install Firebug or use the Firefox error console to know what's wrong with your JS.

      anandhakrishnan wrote:

      var paramname=document.getElementById('<%=txtParam.ClientID %>');

      I am not sure, but I think the client id used in external JS will not get rendered. Have you checked? If it is not rendering, just pass the id as function parameter. Something like

      function validateParameter(textBoxId)
      {
      var paramname = document.getElementById(textBoxId);
      ....
      }
      OnClientClick="javascript: return validateParameter('<%=txtParam.ClientID %>');"

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      • A anandhakrishnan

        Hi, I have written the javascript function in the External js file and named it as JScript.js. This file is in Javascripts folder which under the Project folder. The JScript.js file contains the following code. // JScript File function validateParameter() { var paramname=document.getElementById('<%=txtParam.ClientID %>'); var message; message=""; if(paramname.value=="") { message+="\n*Parameter Name is mandatory"; } else if(paramname.value!="") { var alphaExp = /^[a-zA-Z\s]+$/; if(!paramname.value.match(alphaExp)) { message+="\n*Only Alphabets are allowed for Parameter Name"; } } if(message!="") { alert(message); return false; } return true; } I have called the javascript file using the below html tag. I have called the javascript function for OnClientClick of a button. OnClientClick="javascript: return validateParameter();" But during the runtime the button click is not validating the controls. Please Help Me! Thanks.

        A Offline
        A Offline
        Abhijit Jana
        wrote on last edited by
        #3

        anandhakrishnan wrote:

        I have called the javascript file using the below html tag. I have called the javascript function for OnClientClick of a button. OnClientClick="javascript: return validateParameter();"

        First try with alert on that method and check weather its called or not. Then You should pass the clientID also to the ValidateParameter().

        anandhakrishnan wrote:

        OnClientClick="javascript: return validateParameter();"

        OnClientClick="javascript: return validateParameter(ClientID);"

        cheers, Abhijit CodeProject MVP My Recent Article : Exploring Session in ASP.Net

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups