Solved

Manipulate Div Tags in Code behind file in ASP.NET

Posted on 2007-04-02
3
12,812 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Run time Error 4 49
Gridview selected row 9 47
ASP.NET gridview select textbox on focus 2 37
ASP.NET MVC 2 32
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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

832 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