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
Asked
Active
Viewed 483 times
0
-
You want to hide them in Visual Studio or in the application? – GôTô Feb 23 '17 at 11:09
-
In Visual studio so I can place another page below it – The_Unmarried_Mother Feb 23 '17 at 11:10
-
In the C# code? – The_Unmarried_Mother Feb 23 '17 at 11:12
-
Just to clarify this further. You've got some existing buttons and lables in your designer, and you need to place an element underneath that, currently as you try to do that your buttons and lables end up being covered by that element. Is that correct? – J. Tuc Feb 23 '17 at 11:14
-
I want to create like a menu where when you click on one button everything dissapears and the elements lying underneath will be visible. – The_Unmarried_Mother Feb 23 '17 at 11:15
-
or is there an easier way to accoplish that ( like making another window) – The_Unmarried_Mother Feb 23 '17 at 11:15
2 Answers
0
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>

PriyankaLT
- 15
- 1