Javascript 所需字段验证器上ASP.NET标签的可见性
我有一个不可见的asp.net标签。Javascript 所需字段验证器上ASP.NET标签的可见性,javascript,asp.net,requiredfieldvalidator,Javascript,Asp.net,Requiredfieldvalidator,我有一个不可见的asp.net标签。 在DB中插入内容时,我将其设置为visible=true,并显示一条消息“Record saved”,并且在未触发另一个服务器端事件之前,该内容保持可见。 但问题是,当我再次单击insert时,字段验证器调用并给出如下消息 Please fill all the fields. Record saved. 您可以将其添加到页面底部 <body> <asp:Label runat="server" ID="Label1"><
在DB中插入内容时,我将其设置为
visible=true
,并显示一条消息“Record saved”,并且在未触发另一个服务器端事件之前,该内容保持可见。 但问题是,当我再次单击insert时,字段验证器调用并给出如下消息
Please fill all the fields.
Record saved.
您可以将其添加到页面底部
<body>
<asp:Label runat="server" ID="Label1"></asp:Label>
<script>
//hide the label after 3 seconds
window.setTimeout(function(){
document.getElementById('<%= Label1.ClientID %>').style.display = 'none';
}, 3000);
</script>
</body>
//3秒钟后隐藏标签
setTimeout(函数(){
document.getElementById(“”).style.display='none';
}, 3000);
请记住,在需要时再次将其设置为从代码隐藏处可见当用户单击“插入”按钮时,只需在客户端隐藏标签即可
<asp:Label runat="server" ID="Label1" Visible="False"></asp:Label>
<asp:Button runat="server" ID="btnInsert" OnClientClick="hideLabel();" OnClick="btnInsert_OnClick" ValidationGroup="InsertValidation" CausesValidation="True" />
<script>
function hideLabel(){
document.getElementById('<%= Label1.ClientID %>').style.display = 'none';
}
</script>
您可以使用
ValidatorCalloutExtender
来使用“弹出窗口”来显示错误消息,或者使用ValidationSummary
来列出所需的所有验证错误。单击“插入”按钮,添加一个隐藏该标签的javascript函数如何?如果用户因为盯着天花板而错过了消息,该怎么办?这有点麻烦。
protected void btnInsert_OnClick(object sender, EventArgs e)
{
Label1.Visible = true;
}