如何使链接按钮隐藏并显示占位符 [英] How to make link button hide and show placeholder

查看:126
本文介绍了如何使链接按钮隐藏并显示占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用链接按钮,但它不能使占位符像普通按钮一样可见和隐形



请帮助



我尝试过:



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

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

推荐答案

它无法正常工作的原因是这是发生了什么:

1。首次加载页面,控件不可见。太棒了。

2.点击后,控件可见。太棒了。

3.在后续点击中,控件仍然可见= true,因为在第三次点击时发送回服务器的viewstate可见= true,因此您没有对可见性进行任何有效的更改。 />


请改为尝试:

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:
protected void link1_Click(object sender, EventArgs e)
{
    placeHolder1.Visible = !placeHolder1.Visible;
    textBox1.Visible = !textBox1.Visible;
}





更新:

请注意占位符可见性OVERRIDES全部控制其中的可见性。

因此,从技术上讲,你只需要将PlaceHolder的Visible属性设置为True或False。



为了使其工作,你必须指定占位符默认值为Visible value。



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.


这篇关于如何使链接按钮隐藏并显示占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆