• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 580
  • Last Modified:

Set width of <Table> from code-behind

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
volking
Asked:
volking
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
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
 
Carl TawnSystems and Integration DeveloperCommented:
Oops, didn't see the VB tag.

Code-behind for VB:

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

Open in new window

0
 
Shaun KlineLead Software EngineerCommented:
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
 
volkingAuthor Commented:
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: CompTIA Healthcare IT Tech

This course will help prep you to earn the CompTIA Healthcare IT Technician certification showing that you have the knowledge and skills needed to succeed in installing, managing, and troubleshooting IT systems in medical and clinical settings.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now