Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Set width of <Table> from code-behind

Posted on 2010-11-12
4
Medium Priority
?
548 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 2000 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 27

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

RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

Question has a verified solution.

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

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…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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