Include JavaScript source file in ASP.NET 2.0 web page

I was trying to work on CustomValidator control for the past few days and I have finally able to use it without facing anymore major problem (IMHO). During the development, I found out that the <script> tag, which can be used to reference to a JavaScript source file (.js extension), could affect the post back event of the ASP.NET page.

I have functions written within a JavaScript source file that would be referenced by CustomValidator.ClientValidationFunction properties. I included the source file within the <head>...</head> section with this line of code:

<script type="text/javascript" src="formValidation.js"/>

It is technically correct, isn't it? Since we are allowed to do <tag_name/> in the XML schema, so I would expect that this would work. Yes, indeed that my CustomValidator object is able to fire the client-side validation function, but yet the Submit button would not fire its OnClick event. So I tried to search for solutions on the net, and trying to analyze the examples that I could find.

To my amazement, the problem to this cause is because of the way that I inserted the <script> tag as shown above. So, I inserted it again as follow:

<script type="text/javascript" src="formValidation.js"></script>

And the Submit button would now fire its OnClick event. I'm totally stunt that such syntax would create problem to something that I would expect to work.

This happens within Internet Explorer 6. I still haven't try this problem on Internet Explorer 7.

Comments

Popular posts from this blog

Yahoo! Messenger voice call & video call disabled, why?

Sport's Injuries - Treatment for bruises

Web Development: Disable, Validate, & Enable Buttons