Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/278.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法修改控件集合,因为控件包含代码块(即<;%…%>;)错误_C#_Asp.net_User Controls - Fatal编程技术网

C# 无法修改控件集合,因为控件包含代码块(即<;%…%>;)错误

C# 无法修改控件集合,因为控件包含代码块(即<;%…%>;)错误,c#,asp.net,user-controls,C#,Asp.net,User Controls,代码应该可以工作,但它给了我这个错误。。反汇编显示“AjaxControlToolkit.ExtenderControlBase.OnLoad(System.EventArgs)” var timeoutID; 函数delayedAlert(){ document.getElementById(“”).style.display='inherit'; timeoutID=window.setTimeout(labelhide,3000); } 函数labelhide(){ document.ge

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

var timeoutID;
函数delayedAlert(){
document.getElementById(“”).style.display='inherit';
timeoutID=window.setTimeout(labelhide,3000);
}
函数labelhide(){
document.getElementById(“”).style.display='none';
}
文本框

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

标签


如果暂时忘记了导致错误的原因,结果是页面抱怨无法呈现它,因为找到了直接呈现到页面的字符串的

一种解决方案是使用
Literal
控件,并在我们喜欢的代码后面进行渲染

例如:

function delayedAlert() {
    document.getElementById('<asp:Literal runat="server" id="txtTheId" EnableViewState="false" />').style.display = 'inherit';
        timeoutID = window.setTimeout(labelhide, 3000);
}
<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';
}
当然,这只是绕过错误的想法,您可以在代码背后呈现完整的javascript,注册脚本,或者只将id呈现为变量

例如:

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

UpdatePanel中是否有可能重复的内容?@Aristos我不这么认为。@user2484066请使用“相信”一词表示您无法确定的想法,您是否接受它。这里我们有一个“我知道它在UpdatePanel内,或者我知道它不是,或者我知道它在头文件内而不是在UpdatePanel内”@user2484066好的,要解决这个问题,使用一个文本控件并在那里呈现id,或者完整的javascript(并删除)。Header不喜欢它们。你能给我解释一下隐藏的代码是什么吗?我将代码的代码放在哪里?@user2484066将其放在
PageLoad
<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 + "';";