ASP.net hide panel using javascript

I have a radioButtonList with two elements in it. A beacon with a value of Yes and a radial button with a value of No.

Below I have a panel that I want to make visible when "Yes" radioButton is selected and hidden when "No" is selected. I initially implemented this using the AutoPostBack attribute, but I want to do this in Javascript so that it does not cause a postback. Here is the code. Any help would be greatly appreciated.

<asp:RadioButtonList ID="rbl1" runat="server" onClick="changed(this);" >
<asp:ListItem Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>

<asp:Panel ID="panel1" runat="server">
<--other controls here -->
</asp:Panel>

function changed(rbl) {
        //not sure what to put in here
    }

Thanks in advance,

wants to give Petersburg

+3
source share
5 answers

Here is a brief example that I compiled:

<!-- Used grouped radio buttons instead of the RadioButtonList as it is harder to deal with -->
<asp:RadioButton ID="rbYes" runat="server" Text="Yes" GroupName="YourGroupName" Checked="true" />
<asp:RadioButton ID="rbNo" runat="server" Text="No" GroupName="YourGroupName" />        
<br /><br />    
<!-- Use a div instead of a panel.  Panels are just glorified divs. -->
<div id="divTest">
    This is a test
</div>

<script type="text/javascript">
    $(document).ready(function()
    {
        $('#<%= rbYes.ClientID %>').click(function() { $('#divTest').show(); });
        $('#<%= rbNo.ClientID %>').click(function() { $('#divTest').hide(); });

    });
</script>
+2

    function OnclickPanelHide() {
        if (this.value == "No") {
            document.getElementByID('<%=panel1.ClientID%>').style.display = "none";
        }
        else {
            document.getElementByID('<%=panel1.ClientID%>').style.display = "block";
        }
    }


</script>

Raja ,

+1

"panel1", jQuery, :

$('idOfPanel').hide();

jQuery, id div/panel:

idOfPanel.style.display = "none";

:

$('idOfPanel').show();

idOfPanel.style.display = "block";
0

:

if (this.value == "No")
{
document.getElementByID('<%=panel1.ClientId%').style.display = "none";
}
else
{
document.getElementByID('<%=panel1.ClientId%').style.display = "block";
}

, .

0

, UpdatePanel ( , , -).

0

Source: https://habr.com/ru/post/1736669/


All Articles