简体   繁体   中英

check in .cs page and displaying in .aspx

In my .cs page i want to check some condition and depending on that i will show/hide a div in my .aspx page. Is that possible?

like

if(j==0)
{
div id="hi".visible=false; //something like that
}

I hope u guys understood the problem.

Thank you

.aspx.cs

if (j == 0)
{
  hi.visible = false;
}

.aspx

<div id="hi" runat="server"></div>

Please note, the "runat" sttribute is the important part. This allows it to be accessed in the .cs file.

You need to add runat="server" to the <div> in the .aspx page and then you can access it directly in your code behind. Like so:

Page.aspx:

<!-- ... -->
<div id="hi" runat="server">
  Content Here
</div>
<!-- ... -->

Page.aspx.cs:

// ...

if (j == 0)
{
    hi.Visible = false;
}

//...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM