.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Need help with Javascript in a separate .JS file

Posted By:      Posted Date: October 09, 2010    Points: 0   Category :ASP.Net

I have searched hundreds of posts over countless forums, but am unable to run a Javascript that is placed in a separate .js file. If the script is placed directly in the <HTML>, the script runs fine.


I have simplied the example down to an .aspx page with a single button and the codebehind in VB. I am currently running VWD 2010 on the .Net 4 framework. I've been working on this problem on and off over the past 3 weeks and simply cannot get it to work, so I continue to insert the code directly into the markup. I have tried countless changes to the following code, but not once able to get it to work.

Any help, suggestions or recommendations will be graciously accepted and very much appreciated.


The .aspx page is as follows:


<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test_Script.aspx.vb" Inherits="Test_Script" %>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">


View Complete Post

More Related Resource Links

How to get Selected RadioButton item in a separate javascript file ?



in aspx page i have radio button list as follows:

<input type="radio" name="cb" value="Yes" id="abc" />Yes<br />
                     <input type="radio" name="cb" value="No" />No<br />
                     <input type="radio" name="cb" value="Can't Say" />Can't Say

In a separete javascript file i want to get the selected Radio's value.Can you tell how to get that ?

I have done like this but its showing error:

function getRadioValue()
    var x=document.getElementById(cbbp).value;


>>>How to use javascript function in aspx file?



I have a file util.js and there some funtions in same file.

For example functions name are keyUp, keyDown, isNumeric, isAlphaNumeric

I have used these functions in aspx code behind in a textbox to restrict user that he may not be able to input any special character.

Before, I used the code directly in aspx file but I have do it for different textboxes therefore to avoid much coding in aspx file I created util.js and put all code in this file but how to use these particular functions in aspx file I couldn't find the way.

Anyone have idea. Do share with me.

I used the reference like this:


' Font-Names="Verdana" Font-Size="8pt" Onkeyup= "keyUp(event.keyCode)" Onkeydown="return isAlphaNumeric(event.keyCode);" onpaste="return false;">

How to include a javascript file in a custom action?

I need to call a custom javascript function from a ribbon button, how do I include the javascript file within the custom action solution in order that it will be properly referenced by the html output? I am not allowed to define a custom masterpage at this point. So what can I do?   Thanks, Stephan  

Access Javascript from an aspx file through another aspx file

Hello, So.. I have a file called myFile.aspx which is linked to a js file called myJS.js    There is a file linked to an entirely different frame called theOtherFile.aspx.  I want to access a function is myJS.js called myFunc in theOtherFile.aspxI am not entirely sure how I would accomplish that..I am quite new to MVC2 and JS, so I am quite confused as to how to do this.  Any suggestions would be much appreciated.~Anath

Import a flat file with combined data into separate SQL tables using SSIS

I have a flat text file (comma delimited) that is essentially multiple files, each with its own format, combined into one file. The file is coming from an external software vendor so unfortunately we don't have much choice but to work with what we are receiving. Here is an example of what the file could look like: Customer Data CustID,FName,LName,PhNum,Email 12345,John,Smith,,jsmith@gmail.com 12346,Jane,Doe,8001111111,jdoe@hotmail.com Customer Plan CustID,PlanType,PlanName,PlanStart 12345,0,Plan1,01/01/2010 12345,2,PlanVis,01/01/2010 12346,3,PlanLf,04/01/2010 12346,0,Plan1,01/01/2010 Customer Payment CustID,LastPayment,Amount 12345,09/01/2010,100.00 12346,05/01/2010,50.00 There is an empty line between each 'section' of data. I adapted a VB script I found online that can take the incoming file and save off each section as its own file so that each one can be separately imported, but this seems inefficient. I'm really new to SSIS in general, but it seems like it shouldn't be that difficult to take the data, split it where there is an empty line, and then import each section into the appropriate SQL table. Any ideas would be most welcome. Thanks!  

How to call javascript from file

Hi, i want to call javascript from file JScript.js. I write in head section (in master site) code <script src="JScript.js" type="text/javascript"></script>. How i can call this file from default.aspx(not from master site)? Everything is fine then all code is in master page, but i need this script in other pages.<asp:DataList ID="DataList1" runat="server" RepeatColumns = "2"  RepeatLayout = "Table"  Width = "500px">     <ItemTemplate>         <br />         <table cellpadding = "5px" cellspacing = "0">         <tr>             <td>                 <asp:Image ID="Image1" runat="server" ImageUrl = '<%# Eval("FilePath")%>'                  Width = "200px" Height = "200px" onclick = "LoadDiv(this.src, this)" style ="cursor:pointer" />             </td>         </tr>         </table>         <br /> 

Cached Javascript file using feature VS 2010 - Bug?

Hi, I am using a custom action in an element.xml to reference an external script in my SP2010 solution - by adding a SP 2010 layouts folder and adding the script in there. Everything deploys and runs fine, however, if i update the javascript file and redeploy the solution, when debugging the javascript, the old (non updated) file is loaded and executed. I have tried retracting the feature and re-deploying, cleaning the solution, rebuilding and deploying, yet the javascript file loaded dynamically is still the old file. It seems to be updated intermittently, however, this is quite awkward as I cannot accurately guage when the file is refreshed. I am closing the IE window after every debug session.  Is there a process I should be following to ensure that the script is updated every time? Any help would be greatly appreciated. Cheers.      

How to update JavaScript in SharePoint Ribbon Elements.xml file?


I created Elements.xml file that added button to Ribbon of Web Part page.
I created <CommandUIHandler tag and put JavaScript into CommandAction.
Everything works.

I inserted changes to JavaScript and built and deployed project in VS2010.
The button function was not changed the previous JavaScript was used. I uninstalled feature and rebuilt and redeployed project. The button functionality was not changed again.

What I have to do that JavaScript changes work in CommandAction?

Thank you in advance for any help.

Boris Nossov

Read Excel file to datatable using javascript


I have an asp.net website. I have to upload data from an excel file on the client machine to sql server. I save the excel file on the server where webstie is hosted and try to read from that excel. But users dont have read permission on the server. So i need to read the excel on the client side using javascript and populate the datatable so that i can use that datatable in sql bulk copy to populate my sql tables. so how to read entire excel in javascript and populate to datatable

How to get client id at external javascript file


hello. when i try to get client id with embedded javascript function i can get with this way


document.getElementById('<%=buttonXXX.ClientID%>' )


but i created an external js file and now i am calling it

but this code does not work any more at external javascript file 


any help is appreciated


using asp.net 2.0 , netframework 3.5 , c# , iis 7.5

thank you

Attach File causing JavaScript error on Custom Form

Let me first apologize for this fairly large post. I've basically laid out the problem I'm having and then how I solved it initially then what the final problem.  The reason I put all of the steps is because I am open to any suggestions about handling this different.  If you want to skip to the actual problem, scroll down until you see the text "-----Go here if you want to see the actual problem-----"

Okay, so now the problem:
I have a lookup field called Room Name in a calendar that is looking data up from a list of rooms.  I have programmatically set the permissions of the room name list items to only allow members of different groups to see certain items.

When people go to the calendar and create a new event, they can only choose rooms that I set their group as having permission to choose.  This works great, but it has an unfortunate side effect.  When viewing an event on the calendar, if you are not of a memeber of the group that has read permissions for the item selected in Room Name, you can't see it.  This makes sense internally because of the way I set permissions.  For each item in the list of rooms, if you are a member of a group that should be able to read that item, I give you read permission, otherwise you have no permission for it.

Unfortunately, the viewing of the events is done by people other than those who create the

Embedded Javascript File in Custom Server Control



I am creating a custom server control, and I am wanting to include a JavaScript file in the dll file when the control is built. I have tried suggestions from the following websites:




But after following the directions, If I use firebug to see what errors show up, the JavaScript functions that are being called all say "goNext is not defined" which leads me to believe the JavaScript file is not being added correctly. 

Some information on what my control looks like

I have the JavaScript File in a folder called Script. The namespace of the project is CustomControl, and the Name of the project is MaskedDateTextbox.

In my AssemblyInfo I have the following:

Reference Dynamically Created JavaScript File


I would like to dynamically create, and reference, entirely different JavaScript files based on an id.  This is the route I've taken, and it appears to be working.  I guess I'm just curious if there's something obvious I'm missing, or if anybody has a better idea.

On the web page a reference points to what i'm calling a "javascript handler". 

<script type="text/javascript" src="http://localhost:50869/JsHandler.ashx?Id=0001"></script>


I may eventually experiment with routing to make the reference look like this...

<script type="text/javascript" src="http://localhost:50869/js/0001"></script>


But that's besides the point.  Please keep in mind, the following example is very simple and could be accomplished in easier ways.  Its more of a proof of concept, and I will be creating completely different JS files, from begining to end, depending on the Id passed in.

So yeah basically the logic in my JavaScript handler looks like this

var Id = context.Request["Id"];
            using (var sr = new StreamReader("/Forms/0001.js"))
                var chingy = E

how to registry dll file in asp.net (c# or javascript)


hii to all

i have a site thet need to check some dll file in the client registry

how can i check it and if the is no dll how can i add it to the registry


c# or javascript



"Place code in separate file checkbox" is not showing up



I have a strange problem.

When I create a new webform in my projects I cant see the checkbox "Place code in separate file".

Instead VS2008 automatically creates a webform and a codebehind file.

I used to be able too see the checkbox, but one week ago or so, it just disappeared.

I want to be able to use inline code in my projects. Anyone have a clue what the problem might be?

secure javascript file on client browser


hi i want to secure my javascript file on client browser i dont know how to do it. any way to encrept the file and acess decrepted file. so no one can acess my file on browser.

Get file path in javascript


Hello friends,

          In one application I want to pass image file path to image control through JavaScript. Its working fine by manually passing file path to that control. But it's not possible to give manual path every time. So is there any property in JavaScript so that I can give only file name and path should get generated. (i.e. like server.mappath (filename) in asp.net ).Or is  there any other solution?



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend