gpt4 book ai didi

c# - 隐藏和显示标签和按钮

转载 作者:太空宇宙 更新时间:2023-11-03 17:17:44 25 4
gpt4 key购买 nike

我显示了 2 个标签、2 个文本框和 1 个按钮。

当页面加载 NameButton 时(最初会显示)。稍后,当我单击 Button 时,我需要显示 age labeltextbox。我该怎么做?

<ol>
<li>
<asp:Label runat="server" AssociatedControlID="Name">
User name
</asp:Label>
<asp:TextBox runat="server" ID="Name" Width="167px" />
<asp:Button ID="Button1" runat="server" Text="Button" />
</li>
<li>
<asp:Label runat="server" AssociatedControlID="age">age</asp:Label>
<asp:TextBox runat="server" ID="age" TextMode="age" Width="240px" />
</li>
</ol>

按下按钮的代码

protected void Button1_Click(object sender, EventArgs e)
{

}

最佳答案

您可以在服务器端将标签/文本框的 Visible 属性设置为 True。或者,您可以使用 JavaScript 来避免回发到服务器。

OnClientClick 添加到您的按钮:

<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="ShowLabel();"/>

并在页面上声明 JavaScript 函数:

<script type="text/javascript">
function ShowLabel() {
// Note that the client ID might be different from the server side ID
document.getElementById('lblAge').style.display = 'inherit';
}
</script>

最初需要将Label显示样式设置为none

<asp:Label ID="lblAge" style="display: none;" runat="server" AssociatedControlID="age">age</asp:Label>

关于c# - 隐藏和显示标签和按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14455371/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com