locked
Create custom tags? RRS feed

  • Question

  • User-188219181 posted

    Greetings,

      I am very new to ASP.NET and C#, coming from a world of PHP.  I have a (hopefully) simple question.

      I would like to create a sort of customer tag, for example: I want to be able to define an area, like such:


      <table>........<td>CONTENT</td>........</table>


      And be able to put that in an html layout like such:

      <asp:whatever>this is a test</asp:whatever> (?)


      The ideal result would be:

      <table>........<td>this is a test</td>........</table>



      There would be no actual C# in the code, just a basic table layout.


      Any help would be greatly appreciated =]


    -Keith

    Tuesday, October 20, 2009 8:10 PM

Answers

  • User2077888689 posted

    Hi,

    You can directly use HTML tags in ASP.NET markup just like you do in a HTML file. So you want to build table you write,

    <table>

     <tr>

     <td> Some Data </td>

    </tr>

    </table>


    However note that if you manipulate this table in the server side you need to add the following attributes,

    1. runat="server"

    2. id="myTable" - This isn't mandatory since asp.net will generate an Id by itself, however for refering the control in the server side you need this.

    so the above declaration would some thing like this,

    <table runat="server" ID="myTable">

    .............

    </table>

    Asp.Net also comes with <asp:Table> class which will also render the <table> tags. You can use this as well,

    <asp:Table id="myTable" runat="server">
    <asp:TableRow>
    <asp:TableCell>
    Row 0, Col 0
    </asp:TableCell>
    <asp:TableCell>
    Row 0, Col 1
    </asp:TableCell>
    </asp:TableRow>
    <asp:TableRow>
    <asp:TableCell>
    Row 1, Col 0
    </asp:TableCell>
    <asp:TableCell>
    Row 1, Col 1
    </asp:TableCell>
    </asp:TableRow>
    </asp:Table>

    Hope this helps!

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, October 21, 2009 3:38 AM