Link to home
Start Free TrialLog in
Avatar of viola123
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
<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"
        }
    }

Open in new window

Avatar of ororiole
ororiole
Flag of United States of America image

first put a runat="server" attribute in your div tag. Then you can use this code:
chartDiv.Style["display"] = "inline";  //or "none" etc.
Avatar of viola123
viola123

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.
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.

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>

Open in new window

hi,
i dont find OnClientClick attribute in Checkbox tag.
ASKER CERTIFIED SOLUTION
Avatar of viola123
viola123

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial