Solved

Set width of <Table> from code-behind

Posted on 2010-11-12
4
531 Views
Last Modified: 2012-05-10
I have a table
    <table id="myTBL">
        <tr><td>My Text</td></tr>
    </table>

From code behind, in the PreRender event, how do I set the table's width?

Meaning, I want to "EFFECT"
this result ...
    <table id="myTBL" width="200px">
or this result ...
    <table id="myTBL" width="400px">

from page.prerender in code behind

0
Comment
Question by:volking
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
Comment Utility
You'll need to add a "runat" attribute to the table in order to make it a server control. You will then be able to modify its attributes from code-behind:

   <table id="myTBL" runat="server" width="200px">

  // code-behind
  myTBL.Attributes["width"] = "400px";

Open in new window

0
 
LVL 52

Expert Comment

by:Carl Tawn
Comment Utility
Oops, didn't see the VB tag.

Code-behind for VB:

    myTBL.Attributes("width") = "400px"

Open in new window

0
 
LVL 25

Expert Comment

by:Shaun Kline
Comment Utility
An option would be to add the runat="server" attribute to your table.
This would allow you to access the table from the code-behind.
0
 
LVL 5

Author Closing Comment

by:volking
Comment Utility
Thanks ... was too easy ... of course my mind went to all sorts of CTYPE(), FindControl(), etc, instead of the SIMPLE solution. Adding runat="server" worked great.
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

728 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

9 Experts available now in Live!

Get 1:1 Help Now