Show hide div using codebehind

前端 未结 8 2076
难免孤独
难免孤独 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.

提交回复
热议问题