简体   繁体   中英

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

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

<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; style as follows:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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