Show hide div using codebehind

前端 未结 8 2047
难免孤独
难免孤独 2020-12-30 00:29

I have a DropDownList for which I am trying to show a div OnSelectedIndexChanged but it says OBJECT REQUIRED.

I a

相关标签:
8条回答
  • 2020-12-30 01:20

    Another method (which it appears no-one has mentioned thus far), is to add an additional KeyValue pair to the element's Style array. i.e

    Div.Style.Add("display", "none");
    

    This has the added benefit of merely hiding the element, rather than preventing it from being written to the DOM to begin with - unlike the "Visible" property. i.e.

    Div.Visible = false
    

    results in the div never being written to the DOM.

    Edit: This should be done in the 'code-behind', I.e. The *.aspx.cs file.

    0 讨论(0)
  • 2020-12-30 01:22

    You can use a standard ASP.NET Panel and then set it's visible property in your code behind.

    <asp:Panel ID="Panel1" runat="server" visible="false" />
    

    To show panel in codebehind:

    Panel1.Visible = true;

    0 讨论(0)
提交回复
热议问题