Click here to Skip to main content
11,718,589 members (83,765 online)
Rate this: bad
good
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 + ".
";
   }
 
</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 1-Aug-11 19:24pm
tanweer14.8K
Edited 1-Aug-11 19:58pm
Not Active10.2K
v2
Comments
Mark Nischalke at 2-Aug-11 1:59am
   
format your code when posting a question

1 solution

Rate this: bad
good
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.

thanks
sanjeev
  Permalink  
Comments
tanweer akhtar at 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
0 Sergey Alexandrovich Kryukov 651
1 OriginalGriff 210
2 F-ES Sitecore 185
3 Jochen Arndt 160
4 Maciej Los 130
0 OriginalGriff 535
1 Maciej Los 529
2 Richard MacCutchan 440
3 CHill60 415
4 F-ES Sitecore 415


Advertise | Privacy | Mobile
Web01 | 2.8.150901.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