[asp.net] how to display none through code behind

I have tried this

login_div.Style("display") = "none";

But it's not working.how can I set the display of the div to none through code behind, in aspx I have a div:

<div id="login_div" runat="server">

This question is related to asp.net master-pages

The answer is


try this

<div id="login_div" runat="server">

and on the code behind.

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


Since this is a login div, shouldn't the default be to NOT display it. I am going to go ahead and assume then you want to display it then via javascript.

<div id="login" style="display:none;">Content</div>

Then using jQuery:

<script type="javascript">$('#login').show();</script>

Another method you might consider is something like this:

<div id="login" style="display:<%=SetDisplay() %>">Content</div>

And the SetDisplay() method output "none" or "block"


if(displayit){
  login_div.Style["display"]="inline"; //the default display mode
}else{
  login_div.Style["display"]="none";
}

Adding this code into Page_Load should work. (if doing it at Page_Init you'll have to contend with viewstate changing what you put in it)


Try if this works:

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

Examples related to asp.net

RegisterStartupScript from code behind not working when Update Panel is used You must add a reference to assembly 'netstandard, Version=2.0.0.0 No authenticationScheme was specified, and there was no DefaultChallengeScheme found with default authentification and custom authorization How to use log4net in Asp.net core 2.0 Visual Studio 2017 error: Unable to start program, An operation is not legal in the current state How to create roles in ASP.NET Core and assign them to users? How to handle Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause() ASP.NET Core Web API Authentication Could not load file or assembly 'CrystalDecisions.ReportAppServer.CommLayer, Version=13.0.2000.0 WebForms UnobtrusiveValidationMode requires a ScriptResourceMapping for jquery

Examples related to master-pages

how to access master page control from content page Make absolute positioned div expand parent div height MVC 3: How to render a view without its layout page when loaded via ajax? a page can have only one server-side form tag Parser Error: '_Default' is not allowed here because it does not extend class 'System.Web.UI.Page' & MasterType declaration how to display none through code behind Where does error CS0433 "Type 'X' already exists in both A.dll and B.dll " come from? How to include Javascript file in Asp.Net page Master Page Weirdness - "Content controls have to be top-level controls in a content page or a nested master page that references a master page." Can I dynamically add HTML within a div tag from C# on load event?