Click here to Skip to main content
15,900,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using link button but it is not working for making place holder visible and invisible like a normal button

please help

What I have tried:

ASP.NET
<asp:LinkButton ID="link1" runat="server" Text="Forgot Password?" 
OnClick="link1_Click">  
 <br />  
   <asp:PlaceHolder ID="typeEmail" runat="server" Visible="false">  
    <asp:TextBox ID="textbox1" Visible="false" runat="server" AutoComplete="off">  




code behind
C#
protected void link1_Click(object sender, EventArgs e)  
{  
    typeEmail.Visible = true;  
    textbox1.Visible = true;  
}
Posted
Updated 23-Aug-16 0:09am
v2

1 solution

The reason it's not working is this is what's happening:
1. First load of page, controls are not visible. Great.
2. On click, the controls are visible. Awesome.
3. On subsequent clicks, controls are still visible = true, as viewstate sent back to server on third click is visible=true, so you are not making any effective change to visibility.

Try this instead:
C#
protected void link1_Click(object sender, EventArgs e)
{
    placeHolder1.Visible = !placeHolder1.Visible;
    textBox1.Visible = !textBox1.Visible;
}


UPDATED:
NOTE that the placeholder visibility OVERRIDES all controls visibility inside it.
Therefore, technically you only need to set PlaceHolder's Visible property True or False.

In order for this to work then, you must specify the placeholder default Visible value.
 
Share this answer
 
v2
Comments
Member 12618369 23-Aug-16 6:48am    
Thanks I tried this but it still not working
njammy 23-Aug-16 6:54am    
I assure you it works.
Try it on a new page and then fix your own original page step by step.
Member 12618369 23-Aug-16 7:17am    
Thanks I tried it in new empty page but still not working
njammy 23-Aug-16 7:19am    
Please update your question and post the complete page markup and complete code behind.
Member 12618369 23-Aug-16 7:25am    
this the code for new empty page I have tried
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:LinkButton ID="link1" runat="server" CausesValidation="false" Text="Forgot Password?" OnClick="link1_Click">
<br />
<asp:PlaceHolder ID="typeEmail" runat="server" >
<asp:TextBox ID="textbox1" Visible="false" runat="server" AutoComplete="off">


</div>
</form>
</body>
</html>
code behind
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
protected void link1_Click(object sender, EventArgs e)
{
//typeEmail.Visible = true;
//typeEmail.Visible = true;
typeEmail.Visible = !typeEmail.Visible;
textbox1.Visible = !textbox1.Visible;
}
}


I have realised that some problem with link button because I tried button it works fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900