Click here to Skip to main content
15,846,727 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>";


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<html xmlns="">
   <title>How to update an UpdatePanel with JavaScript</title>
   <script type="text/javascript">
   function UpdPanelUpdate()
       __doPostBack("<%= button.ClientID %>","");
   <form id="form1"  runat="server">
      <asp:ScriptManager ID="ScriptManager1" runat="server" />

   <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">
                <uc1:ucTest ID="ucTest1"  runat="server" />
                <asp:Label ID="lbltest" runat="server">
               <asp:AsyncPostBackTrigger ControlID="button" EventName="Click" />

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

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

any help would be greatly appreciated.
Updated 1-Aug-11 20:58pm
[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.

Share this answer
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