Solved

Manipulate Div Tags in Code behind file in ASP.NET

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

624 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