Access an asp:hiddenfield control in JavaScript

前端 未结 6 1762
南旧
南旧 2020-12-21 00:10

What is the best way to access an ASP.NET HiddenField control that is embedded in an ASP.NET PlaceHolder control through JavaScript? The Visible attribute is set to false i

6条回答
  •  余生分开走
    2020-12-21 00:40

    My understanding is if you set controls.Visible = false during initial page load, it doesn't get rendered in the client response. My suggestion to solve your problem is

    1. Don't use placeholder, judging from the scenario, you don't really need a placeholder, unless you need to dynamically add controls on the server side. Use div, without runat=server. You can always controls the visiblity of that div using css.
    2. If you need to add controls dynamically later, use placeholder, but don't set visible = false. Placeholder won't have any display anyway, Set the visibility of that placeholder using css. Here's how to do it programmactically :

      placeholderId.Attributes["style"] = "display:none";

    Anyway, as other have stated, your problems occurs because once you set control.visible = false, it doesn't get rendered in the client response.

提交回复
热议问题