0

我有一个不可见的 asp.net 标签。
当我在数据库中插入一些东西时,我将它设置为visible=true一条消息“记录已保存”
,并且它一直可见,直到没有触发另一个服务器端事件。但问题是,当我再次单击插入时,空字段必填字段验证器会调用并给出类似的消息

Please fill all the fields.
Record saved.
4

2 回答 2

0

当用户单击插入按钮时,只需在客户端隐藏标签

<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>

后面的代码:

protected void btnInsert_OnClick(object sender, EventArgs e)
{
    Label1.Visible = true;
}
于 2013-01-24T15:28:53.670 回答
0

您可以将其添加到页面底部

<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>

并记住在再次需要时将其设置为从代码隐藏中可见

于 2013-01-24T14:09:38.010 回答