Hi Tevin,
Use setTimeout function to specify the time for hiding the label.
First provide a common class name to the Labels. Then loop through it and set the display property to none.
Refer below sample.
HTML
Enter Name:
<asp:TextBox ID="txtName" runat="server" />
<br />
<asp:Button Text="Submit" runat="server" OnClick="Submit" /><br />
<br />
<asp:Label ID="lblMessage1" ForeColor="Green" Font-Bold="true" Text="Form has been submitted successfully."
CssClass="Message" runat="server" Visible="false" />
<br />
<asp:Label ID="lblMessage2" ForeColor="Green" Font-Bold="true" Text="Form has been submitted successfully."
CssClass="Message" runat="server" Visible="false" />
<script type="text/javascript">
function HideLabel() {
setTimeout(function () {
var elements = document.querySelectorAll(".Message");
for (var i = 0; i < elements.length; i++) {
elements[i].style.display = "none";
}
}, 5000);
};
</script>
Namespaces
C#
protected void Submit(object sender, EventArgs e)
{
lblMessage1.Visible = true;
lblMessage2.Visible = true;
ClientScript.RegisterStartupScript(this.GetType(), "alert", "HideLabel();", true);
}
VB.Net
Protected Sub Submit(sender As Object, e As EventArgs) Handles Button1.Click
lblMessage1.Visible = True
lblMessage2.Visible = True
ClientScript.RegisterStartupScript(Me.GetType(), "alert", "HideLabel();", True)
End Sub
Screenshot