Click here to Skip to main content
15,890,043 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I wan't to refresh the javascript code for file which is stored in label control of asp.net,I have tried to declare javascript variable for asp.net control ,but it gives syntax error and this code does not load when project run.
My code is

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>

C#
<script type="text/javascript">
        // jQuery Document
        alert("hi");
        $(document).ready(function ()
        {
        alert("hi");
            setInterval(loadLogRefresh, 10000);
            //If user wants to end session
            $("#exit").click(function () {
                var exit = confirm("Are you sure you want to exit?");
                if (exit == true) { window.location = 'Logout.aspx'; }
            });
        });

        function loadLogRefresh()
        {
            var oldscrollHeight = $("#chatboxRefresh").attr("scrollHeight") - 20; //Scroll height before the request
            $.ajax({
                var Filename = document.getElementById("lblFileName").value;
                url: Filename;
                cache: false;
                success: function(html)
                {
                $("#chatboxRefresh").html(html); //Insert chat log into the #chatboxRefresh div

                //Auto-scroll
                var newscrollHeight = $("#chatboxRefresh").attr("scrollHeight") - 20; //Scroll height after the request
                if(newscrollHeight > oldscrollHeight)
                    {
                        $("#chatboxRefresh").animate({ scrollTop: newscrollHeight }, 'normal'); //Autoscroll to bottom of div
                    }
                },
            });
        });
</script>
Posted
Updated 7-Feb-14 19:05pm
v2

Instead of the below...
JavaScript
$.ajax({
    var Filename = document.getElementById("lblFileName").value;
    url: Filename;
    cache: false;
......

You should do...
JavaScript
var Filename = document.getElementById("lblFileName").value;

$.ajax({ 
    url: Filename;
    cache: false;
......
 
Share this answer
 
Comments
SVT02 8-Feb-14 0:58am    
But now this code does not read file yet
That is a different issue. This issue is solved. Please accept and up-vote.
For the next issue, add another question. You need to debug the code and find out of the values are coming as expected or not.
SVT02 8-Feb-14 1:14am    
Thank You Mr.Tadit.I have just make changes as
var Filename = $("#lblFileName").value;
Welcome and thanks for accepting the answer.
So, did it solve?
JavaScript
var Filename = document.getElementById('<%=lblFileName.ClientID%>').value;
 
Share this answer
 
v2
Comments
SVT02 8-Feb-14 0:28am    
but my code does not load initially

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900