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; //some开发者_运维问答thing 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;
}
//...
精彩评论