Click here to Skip to main content
10,500,000 members (54,898 online)
Rate this:
Please Sign up or sign in to vote.
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 + ".
<!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.
Posted 1-Aug-11 20:24pm
Edited 1-Aug-11 20:58pm
Not Active10.2K
Mark Nischalke 2-Aug-11 1:59am
format your code when posting a question

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

hello Tanweer,

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

tanweer akhtar 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.151126.1 | Last Updated 2 Aug 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100