无法更新标签更新面板外 [英] Unable to Update label Outside Update Panel

查看:205
本文介绍了无法更新标签更新面板外的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了很多时间来研究如何更新面板外更新标签。终于找到的东西,但它不会更新标签。如果我们刷新页面,它工作正常。请让我知道在code或这样做的任何新的方式错误。请在下面找到我的code。我觉得需要多补充一些code脚本经理或DataItem的()
    谢谢你们的答复!
    隐藏文件code

 使用系统;使用System.Collections.Generic;使用System.Linq的;使用的System.Web;使用System.Web.UI程序;使用System.Web.UI.WebControls;公共部分类scriptMgr:System.Web.UI.Page{保护无效的Page_Load(对象发件人,EventArgs的发送)
{
}保护无效timer_Tick(对象发件人,EventArgs的发送)
{如果(ScriptManager1.IsInAsyncPostBack)
{ScriptManager1.RegisterDataItem(LABEL3,你好);
}
}}
}aspx页面 < D​​IV>< ASP:标签ID =LABEL3=服务器文本=krwelkr>< / ASP:标签>        < ASP:的ScriptManager ID =ScriptManager1=服务器>        < / ASP:ScriptManager的>        <脚本类型=文/ JavaScript的LANGUAGE =JavaScript的>在此输入code        。Sys.WebForms.PageRequestManager.getInstance()add_pageLoading(PageLoadingHandler);        功能PageLoadingHandler(发件人,参数){            变种dataItems = args.get_dataItems();
            如果($得到('LABEL3')!= NULL)
                $得到('LABEL3')的innerHTML = dataItems ['LABEL3']。        }
    < / SCRIPT>
        < ASP:的UpdatePanel ID =UpdatePanel1=服务器>
        <&的ContentTemplate GT;        < /&的ContentTemplate GT;
            <&触发器GT;
                < ASP:AsyncPostBackTrigger控件ID =计时器事件名称=嘀/>
            < /触发器>
        < / ASP:的UpdatePanel>
    < / DIV>


解决方案

添加寄存器脚本事件背后code,

 保护无效timer_Tick(对象发件人,EventArgs的发送)
{
   如果(ScriptManager1.IsInAsyncPostBack)
    {
      //ScriptManager1.RegisterDataItem(Label3,你好);
       ScriptManager.RegisterStartupScript(这一点,this.GetType(),setLabelOrAnyName,jQuery的(函数($){$('#LABEL3)文本('不管')});,真正的);
    }
 }

这应该工作。

柜面,如果你不使用的jQuery 库替换code。与简单的JavaScript

I have spent lot of time to investigate how to update label outside Update panel. And finally found something but it does not update label. It works fine if we refresh the page. Please let me know error in code or any new way of doing this. Please find my code below. I think need add some more code for script manager Or dataItem() Thank you guys for reply! Code behind file

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

public partial class scriptMgr : System.Web.UI.Page

{

protected void Page_Load(object sender, EventArgs e)
{
}

protected void timer_Tick(object sender, EventArgs e)
{

if (ScriptManager1.IsInAsyncPostBack)
{

ScriptManager1.RegisterDataItem(Label3, "Hi");
}
}

}
}



Aspx page

 <div>

<asp:Label ID="Label3" runat="server" Text="krwelkr"></asp:Label>

        <asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager>

        <script type="text/javascript" language="javascript">

enter code here

        Sys.WebForms.PageRequestManager.getInstance().add_pageLoading(PageLoadingHandler);

        function PageLoadingHandler(sender, args) {

            var dataItems = args.get_dataItems();
            if ($get('Label3') != null)
                $get('Label3').innerHTML = dataItems['Label3'];

        }
    </script>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>

        </ContentTemplate>
            <Triggers>
                <asp:AsyncPostBackTrigger ControlID="Timer" EventName="Tick" />
            </Triggers>
        </asp:UpdatePanel>


    </div>

解决方案

Add the register script in code behind event,

protected void timer_Tick(object sender, EventArgs e)
{
   if (ScriptManager1.IsInAsyncPostBack)
    {
      //ScriptManager1.RegisterDataItem(Label3, "Hi");
       ScriptManager.RegisterStartupScript(this, this.GetType(), "setLabelOrAnyName", "jQuery(function($) { $('#Label3').text('Whatever')});", true);
    }
 }

This should work.

Incase if you are not using jQuery library replace code with simple javascript.

这篇关于无法更新标签更新面板外的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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