Solved

Set width of <Table> from code-behind

Posted on 2010-11-12
4
534 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
[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
  • 2
4 Comments
 
LVL 52

Accepted Solution

by:
Carl Tawn earned 500 total points
ID: 34121026
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
ID: 34121042
Oops, didn't see the VB tag.

Code-behind for VB:

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

Open in new window

0
 
LVL 26

Expert Comment

by:Shaun Kline
ID: 34121049
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
ID: 34121236
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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML error not understood 5 33
GUID's in SQL Server 4 32
MessageBox Appear behind a form in Runtime 1 32
How does this modal work? 3 34
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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