Why the Jquery doesnt work when I move the code into a separate .js file

Last Reply on Mar 11, 2012 11:20 AM By Mudassar

Posted on Mar 11, 2012 11:18 AM

Hello, I have follow this post and the code works well if i put it under the same page in the script section.

http://www.aspsnippets.com/Articles/Create-dynamic-textbox-using-JavaScript-in-ASP.Net.aspx


However, if i move to a separate js file call admin-btn.js and then it gives me error when it comes to this part of code:
 

 function RecreateDynamicTextboxes() {
        var values = eval('<%=Values%>');
        if (values != null) {
            var html = "";
            for (var i = 0; i < values.length; i++) {
                html += "<div>" + GetDynamicTextBox(values[i]) + "</div>";
            }
            document.getElementById("TextBoxContainer").innerHTML = html;
        }
    }

The message is about sytax error in runtime (sorry it was in chinese..)

Microsoft JScript 執行階段錯誤: 語法錯誤

 

i have put all the code inside here in admin-btn.js
$(document).ready(function () {

//All codes

});

 

Can anyone help me on this? THanks!

Posted on Mar 11, 2012 11:20 AM

Yes it will not work on JS because of <%=Values%>. It is called inline server tags

http://www.aspsnippets.com/Articles/Inline-ASP.Net-Server-Tags.aspx

it gets some values from server side and hence client and server logic is linked.

Thus you will need to put script on page or content page (if using master pages)

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html