Solved

Manipulate Div Tags in Code behind file in ASP.NET

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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 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