简体   繁体   English

使用LinkBut​​ton的onClick peroperty使asp.net控件在客户端显示为true

[英]make asp.net control visible true at clientside using onClick peroperty of LinkButton

I am using ASP.Net Controls like (TextBox, Drop down List) in my UserControl Page and all are make invisible for this i am using (Edit ). 我正在使用我的UserControl页面中的(文本框,下拉列表)等ASP.Net控件,并且我正在使用(编辑)所有这些都是不可见的。 There is a Link Button for Edit in the same page. 在同一页面中有一个用于编辑的链接按钮。 I want to make it visible at clientside. 我想在客户端看到它。 can any one suggest how should i do. 任何人都可以建议我该怎么做。 or any other way to make it. 或任何其他方式来实现它。

To do this with Javascript you'll want to remove the OnClick attribute of the LinkButton and use the OnClientClick attribute to call a Javascript function instead: 要使用Javascript执行此操作,您需要删除LinkBut​​ton的OnClick属性,并使用OnClientClick属性来调用Javascript函数:

<asp:LinkButton ID="lb_link_button" runat="server" Text="Click Me" OnClientClick="return ToggleShowHide()"/>

Here's a corresponding Javascript function to show/hide a control named my_control using its style.display property: 这是一个相应的Javascript函数,用于显示/隐藏名为my_control的控件,使用其style.display属性:

<script type="text/javascript">        
    function ToggleShowHide() {
        var control = document.getElementById("<%= my_control.ClientID %>");
        if (control.style.display == "none") { control.style.display = "block"; }
        else { control.style.display = "none"; }
        return false;
    }
</script>

You can reference the control(s) to show/hide in various ways, this is just a simple example. 您可以通过各种方式引用控件以显示/隐藏,这只是一个简单的示例。

Note, the control(s) to set visible/invisible must not have their Visible property set as false, instead they should be declared with a display:none; 注意,设置visible / invisible的控件不能将其Visible属性设置为false,而应使用display:none; style as follows: 风格如下:

<asp:Control runat="server" ID="my_control" Visible="true" style="display:none;"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM