Solved

Manipulate Div Tags in Code behind file in ASP.NET

Posted on 2007-04-02
3
12,806 Views
Last Modified: 2012-06-27
I have 2 Div tags in my ASPX page and i need to set the height, width of the Div's Based on certain conditions..

How can i achieve this using a C# Code behind file?

What property needs to be set to do this.. I tried using the Div.Style Property but it only allows to apply css style sheets and not set Height, Width ..

Please Help
0
Comment
Question by:Collindsouza
3 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 18834999
You can use the style property:

MyDiv.Style("Height") = "100px";
MyDiv.Style("Width") = "200px";

For example.
0
 
LVL 6

Expert Comment

by:Niraj_Singh
ID: 18835004
hi,
Yes you can do so in your code behind.

Have a runat=server attribute and an ID for your DIV tag to create a
HtmlGenericControl on the server side. Then you can easily set the width or
height of the DIV tag on the server-side itself.

<DIV id="MyDivTag" runat="server"></DIV>

In your code-behind:

MyDivTag.Attributes["style"] = "width:100px; height:200px;";

0
 
LVL 10

Accepted Solution

by:
orbulat earned 500 total points
ID: 18835037
yes, u can set the div's width and height, just like the experts suggested above.

but it will be better for u to change the cssClass instead of hardcoding the height and width in codebehind, so next time if u have style updates, u don't have to compile the codes again.. and the updates can be done in front-end css rather than back-end codes..

e.g.

if (condition1) {
   MyDivTag.CssClass = "class1";
} else {
   MyDivTag.CssClass = "class2";
}

style.css
.class1 {
    height : 100px;
    width : 100px;
}

.class2 {
    height : 200px;
    width : 200px;
}
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Delivering innovative fully-managed cloud services for mission-critical applications requires expertise in multiple areas plus vision and commitment. Meet a few of the people behind the quality services of Concerto.

919 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

16 Experts available now in Live!

Get 1:1 Help Now