Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all,

I am working on a project where I want to refresh a part of the web page where i have a user control that contain dynamic data.user control will load data from a text file as this text file will update frequently. I need to refresh the user control alone not the whole page using javascript. I tried the following but it did not worked for me.

<%@ Page Language="C#" %>

<%@ Register src="ucTest.ascx" tagname="ucTest" tagprefix="uc1" %>

<script  runat="server">

   void button_Click(object sender, EventArgs e)
   {
       lbltest.Text = "Refreshed by server side event handler at " + DateTime.Now + ".<br>";
   }

</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
   <title>How to update an UpdatePanel with JavaScript</title>
   
   <script type="text/javascript">
   function UpdPanelUpdate()
   {
       __doPostBack("<%= button.ClientID %>","");
   }
   </script>
   
</head>
<body>
   <form id="form1"  runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server" />
      <div>
      

   <a href="java<!-- no -->script:UpdPanelUpdate()">Update the Panel</a>
    
    <asp:Button ID="button" runat="server" OnClick="button_Click" style="display:none;"/>
      
         <asp:UpdatePanel runat="server" ID="UpdatePanel1" UpdateMode="Conditional">
            <contenttemplate> 
                <uc1:ucTest ID="ucTest1"  runat="server" />
                <asp:Label ID="lbltest" runat="server">
            </contenttemplate>
            <triggers>
               <asp:AsyncPostBackTrigger ControlID="button" EventName="Click" />
            </triggers>
         
      </div>
   </form>
</body>
</html>
</br>


my user control is.
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ucTest.ascx.cs" Inherits="ucTest" %>
<table border="3">
    <tr>
        <td>
            <%  Response.WriteFile("TextFile.txt"); %>
        </td>
    </tr>
</table>



Here TextFile.txthas some information that will be changed frequently.


any help would be greatly appreciated.
Posted
Updated 1-Aug-11 19:58pm
v2
Comments
[no name] 2-Aug-11 1:59am    
format your code when posting a question

1 solution

hello Tanweer,

you have taken update panel. now why dont you take an timer and use the tick event for refreshing the data.

thanks
sanjeev
 
Share this answer
 
Comments
tanweer 2-Aug-11 2:10am    
thank you SanjeevSingh for your reply.
I don't know how to use the timer here I need just to refresh the usercontrol when I click a button from javascript, that is all my requirement.

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