从javascript的更新面板中刷新用户控件 [英] Refresh user control inside an update panel from javascript

查看:81
本文介绍了从javascript的更新面板中刷新用户控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在一个项目中进行更新,我想刷新网页的一部分,其中我有一个包含动态数据的用户控件.该文本文件会经常更新,因此用户控件将从文本文件中加载数据.我需要单独刷新用户控件,而不是使用javascript刷新整个页面.我尝试了以下操作,但对我没有用.

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>




这里TextFile.txt具有一些将经常更改的信息.


任何帮助将不胜感激.




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


any help would be greatly appreciated.

推荐答案

你好Tanweer,

您已进入更新面板.现在,为什么不使用计时器并使用tick事件刷新数据.

谢谢
sanjeev
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


这篇关于从javascript的更新面板中刷新用户控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆