我尝试使用脚本更新标签。在脚本之后,每个 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>
标签内部和外部更新面板均未更新。