Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 557
  • 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

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

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