skip to Main Content

In my aspx page, I have the following code to generate a asp:Table

abc.aspx

<asp:Table id = "_tableTest" runat="server"></asp:Table>

When I render it on the page , I need the id to be prepend with a text , for example "Address"

<table id="Address_tableTest" > </table>

How can I customize the ID generation? I couldnt find relevant documentation.

2

Answers


  1. You can append it.

    <asp:Table id = '<%# Eval("Id") + "_TableName" %>' runat="server"></asp:Table>
    

    what is the use of Eval() in asp.net

    Yes @VDWWD is correct Id can not be set dynamically

    The ID property of a control can only be set using the ID attribute in the tag and a simple value. Error Generated by webforms when I tried to set it dynamically.

    It is explained here in this post Eval script for server side control’s ID property

    Login or Signup to reply.
  2. What do you mean? If some 3rd party needs the table name, then you can’t change it. I mean, either you type in Address_tableTest as the ID, or you don’t.

    The "id" is NOT generated for you, YOU the developer type it into the markup

    You can change the "id" in the forms pre-render event.

    In fact, you can even change it in the page on-load event.

                this.GridView1.ID = "abc";
    

    or

     GridView1.ID = "Address_" + GridView1.ID.ToString();
    

    The "id" in markup will now thus render and use "abc".

    However, code behind will continue to use "this.GridView1" to reference the control.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search