0

该代码应该可以工作,但它给了我这个错误..反汇编说这个“AjaxControlToolkit.ExtenderControlBase.OnLoad(System.EventArgs)”

 var timeoutID;

    function delayedAlert() {
        document.getElementById('<%= Label3.ClientID %>').style.display = 'inherit';
            timeoutID = window.setTimeout(labelhide, 3000);
    }

    function labelhide() {
        document.getElementById('<%= Label3.ClientID %>').style.display = 'none';
    }

文本框

 <asp:Button ID="Button1" runat="server"  Onclick = "Button1_Click" 
            OnClientClick = "javascript:delayedAlert(); return SubmitForm();" 
            Text="Submit" Width="98px"/>

标签

<asp:Label ID="Label3" runat="server" Text="Entry Successful!" Visible="False" ForeColor="Lime"  ></asp:Label>
4

1 回答 1

0

如果暂时忘记了导致错误的原因,结果是页面抱怨无法渲染它,因为找到<%= %>了直接将字符串渲染到页面。

一种解决方案是使用Literal控件并在我们喜欢的代码后面呈现。

例如:

function delayedAlert() {
    document.getElementById('<asp:Literal runat="server" id="txtTheId" EnableViewState="false" />').style.display = 'inherit';
        timeoutID = window.setTimeout(labelhide, 3000);
}

和后面的代码

txtTheId.Text = Label3.ClientID.ToString();

当然,这只是绕过错误的想法,您可以在后面的代码上渲染完整的 javascript,注册脚本,或者您可以将 id 渲染为变量。

例如:

<asp:Literal runat="server" id="txtTheId" EnableViewState="false" />    
var timeoutID;

function delayedAlert() {
    document.getElementById(Label3ID).style.display = 'inherit';
        timeoutID = window.setTimeout(labelhide, 3000);
}

function labelhide() {
    document.getElementById(Label3ID).style.display = 'none';
}

在你背后的代码上

txtTheId.Text = "var Label3ID='" + Label3.ClientID + "';";
于 2013-06-18T21:51:02.650 回答