从内容页面更新MasterPage上的标签,而没有完整的回发 [英] Update label on MasterPage from content page without full Postback

查看:86
本文介绍了从内容页面更新MasterPage上的标签,而没有完整的回发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否存在针对这种情况的解决方案?

我没有在母版页上使用脚本管理器,因为当我开始开发该项目时不需要,因此我对每个内容页都有单独的scriptmanager和Update面板.在母版页中,我添加了一个标签,该标签显示系统当前时间,我的客户想要它应该异步变化并给人以实时时钟的感觉.我可以使用Timer事件从内容"页面更改母版页的标签文本,该事件不会回发整个页面.

在此先感谢您

Does there exist a solution for this scenario?

I had not used Script Manager on Masterpage as it is not required when i started developing the project so i have individual scriptmanager and Update panel for each content page .In the masterpage now i had added a label which Shows System Current Time and My client want that it should change asynchonously and give a live clock feeling. Can i change the label text of master page from the Content page using Timer event which will not postback the entire page.

Thanks in advance

推荐答案

如果要在母版页中显示当前时间,则可以使用
If you want to show the current time in your master page means you can have a javascript function()to show the time....


JavaScript以在网页上显示连续时间.连续表示它会每秒显示一次.

Javascript to display continuous time on the Web page. By continuous it means that it will be displayed second by second.

<script type="text/javascript">
        function ShowTime()
        {
            var dt = new Date();
            document.getElementById("<%= TextBox1.ClientID %>").value = dt.toLocaleTimeString();
            window.setTimeout("ShowTime()", 1000);
        }


    </script>

<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>




如果您使用的是普通的Webform,则可以在Body load事件中调用它.如果您使用的是MasterPage,则可以在呈现完所有控件后在ContentTemplate中调用它.




If you are using normal Webform then it can be called on Body load event. If you are using MasterPage then it can be called within ContentTemplate at the end afte all the controls will be rendered.



如果不回发页面,则无法更新母版页控件.
将标签放在单独的UpdatePanel中的MasterPage中.
从处理程序中调用MasterPage上的一个函数(即ChangeText),该函数会更改标签的文本,并在MasterPage的UpdatePanel上调用Update.


尝试
讨论1 [ [
Hi,
It''s not possible to update a control of master page without posting back your page.
Put your label in your MasterPage in a separate UpdatePanel.
From your Handler call a function on MasterPage(i.e. ChangeText) that changes the Text of the Label and calls Update on the MasterPage''s UpdatePanel.


Try discusstion1[^] and discusstion2[^].


--Amit


这篇关于从内容页面更新MasterPage上的标签,而没有完整的回发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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