Solved

How to set div.style.display = "inline" in c#?

Posted on 2008-11-02
8
5,449 Views
Last Modified: 2012-05-05
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

0
Comment
Question by:viola123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
8 Comments
 
LVL 16

Expert Comment

by:ororiole
ID: 22863730
first put a runat="server" attribute in your div tag. Then you can use this code:
chartDiv.Style["display"] = "inline";  //or "none" etc.
0
 
LVL 6

Author Comment

by:viola123
ID: 22863791
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?
0
 
LVL 16

Expert Comment

by:ororiole
ID: 22863852
No, it will still work fine with javascript.
0
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 
LVL 6

Author Comment

by:viola123
ID: 22863871
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.

0
 
LVL 6

Author Comment

by:viola123
ID: 22863874
is it possible to do it in javascript?
0
 
LVL 8

Expert Comment

by:mkosbie
ID: 22863951
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

0
 
LVL 6

Author Comment

by:viola123
ID: 22864088
hi,
i dont find OnClientClick attribute in Checkbox tag.
0
 
LVL 6

Accepted Solution

by:
viola123 earned 0 total points
ID: 22864535
hi,
i worked out.

thanks
<html>
<head>
<script type="text/javascript">
<!--
 
function onload() {
   if(!getElementById("cbChart").checked) {
	    getElementById("chartDiv").style.display = "none";
	}
	else{
	    getElementById("chartDiv").style.display = "inline";
	}
   getElementById("cbChart").attachEvent('onchange', SaveRequiredActionCB ); 
}
 
function SaveRequiredActionCB() {
	if(!getElementById("cbChart").checked) {
	    getElementById("chartDiv").style.display = "none";
	}
	else{
	    getElementById("chartDiv").style.display = "inline";
	}
}
//-->
</script>
</head>
 
<body onload="onload()">
<asp:CheckBox runat=server ID=cbChart OnCheckedChanged="cbChart_CheckedChanged" />
<div id="chartDiv" style="position:relative; height:300px; width:300px;"></div>
</body>

Open in new window

0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question