.js files

M

Mantorok

Hi all

I want to seperate my client-side validation into a seperate js file,
unfortunately the .js functions have no concept of document.getElementById,
is it possible to have external javascript files referencing page controls?

Thanks
Kev
 
G

Guest

Hi Kev,

Yes you can define a separate javascript validation file for your
application. By default every .net web application, access the validaiton
file resided in the asp_net_client directory of your wwwroot. But if you want
to write your own js file , you can do that, once you define, all your
validation methods call will forward to that file.

What you have to do is to define a property in the web config file.

<system.web>
<webControls clientScriptsLocation="/script_files/"/>
</system.web>

And now place the WebUIValidation.js in the script_files folder,
 
K

Karl Seguin

I don't understand the initial question, but I'm not sure Wajahat answered
it...

in a .js file, you can do document.getElementById("blah"); just fine...the
script is included in the page and works against that DOM

Perhaps what you are asking is how to get access to ASP.Net ClientIds ?
maybe you have stuff like
document.getElementById('<%=MyControl.ClientID%>'); ??

in this case, no, your .js file doesn't have access to this. The one
solution is in your page create a bunch of js variables:

<script language=JavaScript">
//at bottom of page, or OnLoad event
var username = document.getElementById("<%=UserName.ClientId%>");
....
</script>

and then in your js file, you have access to the "username" javascript
variable...

Karl
 
Joined
Jul 17, 2009
Messages
1
Reaction score
0
i tried creating javascript variables and keeping script in separate file. but i get 'list' not defined...thats the name of the variable i defined in the ascx page.
i implement the separate javascript file because i am using 2 instances of the same user control..and it seems that the javascript is working on that last user control that is added.

please let me know if there is a solution to having 2 instances of user control and working with javascript. i have used the 'clientid' to get unique id..but javascript is working with the last added user control
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,562
Members
45,038
Latest member
OrderProperKetocapsules

Latest Threads

Top