0

我尝试使用脚本更新标签。在脚本之后,每个 Label.value 已经有数据,但它不是在页面更新。这是我的代码:

ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "a", @" <script type='text/javascript'> 
        function bbfb() {
            $.ajax({
                type: 'POST',
                url: 'ImgService.asmx/GetAllImgs',
                data: '{}',
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                async: false,
                success: function (msg) {
                    var cars = msg.d;
                     var TextBoxError = document.getElementById('Labelxyz123');
                     var TextBoxError1 = document.getElementById('LabelLogContent');
                     TextBoxError.value = cars;
                      TextBoxError1.value = cars;
                },
                failure: function (msg) {
                    alert('fail');
                }
            });
        }

        function BindEvents() {
            setTimeout(function () {
                bbfb();

            //At this point, all of the labels already have data
            var TextBoxError = document.getElementById('Labelxyz123');
            var TextBoxError1 = document.getElementById('LabelLogContent');
            alert(TextBoxError.value);
            alert(TextBoxError1.value);
            //

            }, 0);
        }
        BindEvents();

</script>", false);
            UpdatePanelEdit_on.Update();

这是我的asp代码:

<asp:Label ID="Labelxyz123" runat="server" ClientIDMode="Static" Text="a"></asp:Label>

    <asp:UpdatePanel ID="UpdatePanelEdit_on" runat="server" UpdateMode="Conditional"
        ChildrenAsTriggers="false">
        <ContentTemplate>
        <asp:Label ID="LabelLogContent" ClientIDMode="Static" runat="server" Text="a"></asp:Label>
    </ContentTemplate>
        <Triggers>
        </Triggers>
    </asp:UpdatePanel>

标签内部和外部更新面板均未更新。

4

1 回答 1

0

我终于找到了我的问题。解决此问题的方法是将 async 更改为 true

 async:true

改变

var TextBoxError = document.getElementById('LabelLogContent');
TextBoxError.value = cars;

进入

$('#LabelLogContent).Text = cars

问题是标签没有从客户端更新。

于 2013-11-01T02:33:37.900 回答