Hide labels and buttons while working in wpf

I want to hide Labels and buttons while working with my code in WPF C# (using Visual Studio) Is there any way I can do this

Upvotes: 0

Views: 520

Answers (2)

PriyankaLT
PriyankaLT

Reputation: 15

Aspx page:
___________
Enter Name:
<asp:TextBox ID="txtName" runat="server" />
<br />
<asp:Button Text="Submit" runat="server" OnClick="Submit" /><br />
<br />
<asp:Label ID="lblMessage" ForeColor="Green" Font-Bold="true" Text="Form has been submitted successfully." runat="server" Visible="false" />

Below is the code to make the Label visible on button click.
_________________________________________________________
protected void Submit(object sender, EventArgs e)
{
    lblMessage.Visible = true;
    ClientScript.RegisterStartupScript(this.GetType(), "alert", "HideLabel();", true);
}

Automatically Hiding Label control after 5 seconds using JavaScript
___________________________________________________________________
Below is the JavaScript function that will hide the Label after 5 seconds. This function gets called using ClientScript RegisterStartupScript method when the Button is clicked.
A variable seconds holds the value which determines after how many seconds the Label will hide. You can set whatever value you need in seconds as per your requirement.
Finally within JavaScript setTimeout function, the Label is hidden by setting its CSS display property to none and the timeout is specified by multiplying the ‘seconds’ variable to 1000 as setTimeout function accepts value in Milliseconds.

<script type="text/javascript">
    function HideLabel() {
        var seconds = 5;
        setTimeout(function () {
            document.getElementById("<%=lblMessage.ClientID %>").style.display = "none";
        }, seconds * 1000);
    };
</script>

Upvotes: 0

G&#244;T&#244;
G&#244;T&#244;

Reputation: 8053

You can add the attribute d:IsHidden="true" on these elements.

See this post:

  • add if not already present xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  • put d:IsHidden="true" on element you want to hide at design time only

Upvotes: 1

Related Questions