locked
Want to close asp panel on tab click RRS feed

  • Question

  • User646364117 posted

    When I click tabs-15 I want to close an asp panel that's 'on' that tab.

    <asp:Panel ID="pnlBuildBlockInsert"

    How would I do that? TIA

    JQuery stub

    $("#tabs-15").click(function () {
                
            });

    Thursday, February 13, 2020 6:47 PM

All replies

  • User-474980206 posted

    what does close mean? what tabs technique are you using?

    note: an asp:panel is just a div

    Thursday, February 13, 2020 9:00 PM
  • User646364117 posted

    Sorry if I wasn't clear. What I meant was that I want to make a panel not visible when I land on the tab that it lives on.

    The following code did what I wanted. I realized that clicking on any tab should make it not visible. So problem solved.

    $("#tabs-right").click(function () {
                $("#pnlBuildBlockInsert").hide();
                   
            });

    Thursday, February 13, 2020 9:10 PM
  • User1738843376 posted

    Be aware that controls inside Pages (ASPx )that are under MasterPages, and controls that are inside UserControls (ASCx) will tipically generate a distinct ID from the one that you declared in your ASPx Control, meaning that you are better of injecting code from the server like:

    $("#tabs-right").click(function () {
        $("#<%=pnlBuildBlockInsert.ClientID%>").hide();
    });

    This approach will prevent the Javascript/JQuery selectors from missing their target that by then might have an ID like mainContent_ctrlUserBar_pnlBuildBlockInsert.

    Friday, February 14, 2020 3:30 AM
  • User646364117 posted

    Thank you. I changed my code, even though I am not using master pages. I have found that they cause a lot of complication when trying to find controls, etc.

    Friday, February 14, 2020 3:13 PM
  • User288213138 posted

    Hi sg48asp,

    Thank you. I changed my code, even though I am not using master pages. I have found that they cause a lot of complication when trying to find controls, etc.

    If you want to find the control in jquery, you can try to use the selector with a filter. If you see the generated id attributes they all end with the ID property of every control.

    for example, below code will click the Button1.

    <script type="text/javascript">
        jQuery("input[id$=Button1]").click();
    </script>

    More information about how to find the control in jquery you can refer to this link:

    https://codingstill.com/2011/02/asp-net-jquery-and-clientid/

    Best regards,

    Sam

    Monday, February 17, 2020 2:47 AM