Click here to Skip to main content
15,924,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
The posting of the data always flashes the correct data but it does not stay in the div. I tried putting "return false;" that did not work. I think it has to do with the "runat='server'" in ASP.net.

How do I keep the Ajax data on the screen after a initial correct flash?

ASP.NET
<script type="text/javascript" src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
    $(function () {
        $("#<%= Button1.ClientID %>").bind("click", fromServer)
    });
    function fromServer() {
        $.ajax({
            type: "GET",
            url: "textFromServer.txt",
            success: postToPage
        });
    }
    function postToPage(data, status){
        $('#servertext').text(data);
    }
</script>
<asp:Button ID="Button1" runat="server" Text="Get Text" /><br />
<div id="servertext"></div>
Posted
Updated 3-Dec-14 11:17am
v2
Comments
ZurdoDev 3-Dec-14 22:26pm    
You can add OnClientClick = "fromServer(); return false;" instead of using jQuery to bind the click event.

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