viola123
asked on
How to set div.style.display = "inline" in c#?
hi all,
i have a div and check box in web page, when check box is ticked, that div will be displayed on the page, otherwise, div is hidden. how to do it in c# code?
thanks a lot
viola
i have a div and check box in web page, when check box is ticked, that div will be displayed on the page, otherwise, div is hidden. how to do it in c# code?
thanks a lot
viola
<asp:CheckBox runat=server ID=cbChart OnCheckedChanged="cbChart_CheckedChanged" />
<div id="chartDiv" style="position:relative; height:300px; width:300px;"></div>
------------------------------
protected void cbChart_CheckedChanged(object sender, EventArgs e)
{
if (cbChart.Checked)
{
//how to set div to inline in c#?
//getElementById("chartDiv").style.display = "inline"
}
}
ASKER
i need to use this div in both javascript and c#, so if i put a runat="server" attribute in my div tag, will it affect my client javascript?
No, it will still work fine with javascript.
ASKER
hi,
i tried this solution, i got error when trying to draw a chart and put it into the Div. it seems the javascript cannot recognize the Div when i put a runat="server" attribute in its tag.
i tried this solution, i got error when trying to draw a chart and put it into the Div. it seems the javascript cannot recognize the Div when i put a runat="server" attribute in its tag.
ASKER
is it possible to do it in javascript?
Yes, it's very easy in JS. Here's a sample DIV:
<html>
<head>
<script type="text/javascript">
<!--
function sh(obj) {
if(obj.style.display == "none") obj.style.display = "inline";
else obj.style.display = "none";
}
//-->
</script>
</head>
<body>
<asp:CheckBox runat=server ID=cbChart OnClientClick="sh(document.getElementById('chartDiv'));" />
<div style="position:relative; height:300px; width:300px;" id="chartDiv">This is text in the chart DIV</div>
</body>
</html>
ASKER
hi,
i dont find OnClientClick attribute in Checkbox tag.
i dont find OnClientClick attribute in Checkbox tag.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
chartDiv.Style["display"] = "inline"; //or "none" etc.