C# within HTML

M

Mike P

I have a HTML menu that I want to add some C# code around which will
include a variable declaration and an if statement. How do I add this
code within my HTML?

*If statement here, if true then show div
<div id="idButton3" class="otherLeftBarLink" onmouseover="javascript:
changeStylesMouseOver('3');" onmouseout="javascript:
changeStylesMouseOut('3');" onclick="location='/AllProjects.aspx'">
<div class="leftBarLinkText">
All Projects
</div>
</div>
*If statement here, if true then show div
<div id="idButton4" class="otherLeftBarLink"
onmouseover="javascript: changeStylesMouseOver('4');"
onmouseout="javascript: changeStylesMouseOut('4');"
onclick="location='/MyProjects.aspx'">
<div class="leftBarLinkText">
My Projects
</div>
</div>
 
C

clintonG

There are several approaches but for you perhaps the easiest to understand
and implement could be the following:

<div id="idButton3" runat="server"
style="visibility:hidden">
....
</div>
<div id="idButton4" runat="server"
style="visibility:hidden">
....
</div>

You are telling the compiled each div is now an HTML Control. By default
each control is not visible at runtime. In code you are going to determine
which control should be visible and displayed. The source for each div will
remain visible in the HTML but only one HTML control will be displayed and
active on the UI at runtime...

// Your C# code...
#region Task: Determine display of idButtons...
HtmlGenericControl button3 =
FindControl("idButton3") as HtmlGenericControl;
HtmlGenericControl button4 =
FindControl("idButton4") as HtmlGenericControl;

// determine which to make visible
if(some condition is true)
{
button3.Visible = true;
}
else
{
button4.Visible = true;
}
#endregion

<%= Clinton Gallagher
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top