Click here to Skip to main content
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 20:24pm
tanweer14K
Edited 1-Aug-11 20:58pm
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 Kornfeld Eliyahu Peter 275
1 Maciej Los 204
2 Sergey Alexandrovich Kryukov 200
3 King Fisher 185
4 OriginalGriff 183
0 OriginalGriff 6,223
1 DamithSL 4,724
2 Maciej Los 4,196
3 Kornfeld Eliyahu Peter 3,894
4 Sergey Alexandrovich Kryukov 3,496


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 2 Aug 2011
Copyright © CodeProject, 1999-2014
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