C# .NET - External javascript doesn't get the value

Asked By karur krishna madhu on 12-Aug-13 07:49 AM
I have written a function in javascript when that function is with in the aspx file i get the value but if i move that to external js file then the value i get is undefined(null).i tried with <%=lblstatus.clientid%>but as <%%> these are aspx delimiters they are identified in aspx but in .js file they are not helpful.

code in aspx :
 <%--<script type="text/javascript" language="javascript">
        function GetTextValue() {

            var box1 = document.getElementById('<%= lblStatus.ClientID %>');
            var box2 = document.getElementById('<%= lblUPO.ClientID %>');
            box2.value = box1.value;



code in external javascript

function GetTextValue() 

    var box1 = document.getElementById('lblStatus').value;
    var box2 = document.getElementById('lblUPO').value;

Robbe Morris replied to karur krishna madhu on 12-Aug-13 08:46 AM
If you set the client id status mode for the page to be static, you can use the ID "you" set for the control and not the dynamically generated one by ASP.NET.

The <% and %> are tags processed during the life cycle of the .aspx page.  They are not processed by when put inside of a .js file.  You could also store the ids of your controls higher up in the .aspx page inside of JavaScript tags but set as global variables and reference them somehow in your .js scripts that come later in the life cycle.