Solved

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

Posted on 2008-11-02
8
5,387 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
  • 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
 
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error in script 11 47
Visual Studio TFS - how do I check in my code? 2 29
Angular - "nest" service calls? 18 24
javascript date picker in php while loop 5 27
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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…

896 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now