How does HnD generate control ID's?

Posts   
 
    
Melp
User
Posts: 2
Joined: 10-Aug-2007
# Posted on: 10-Aug-2007 13:48:43   

Hello all,

I'm fairly new to LLBLGen, and I'm in the process of developing my first two LLBLGen-projects (and introducing it to the rest of our organisation simple_smile ). So far it's going smoothly and I enjoy using this great tool, so no question about LLBLGen itself.

There is one thing that caught my eye about HnD though. When looking at the generated HTML-code in a web browser, I noticed how server controls with an ID don't have the ugly naming container prefixes that are usually automatically created by ASP.Net.

Example (a textbox): HnD: id="tbxSearchString" Other ASP.Net: id="ctl00_phPage_tbxSearchString"

How does HnD do this confused I couldn't find it anywhere, and I've never seen this before. I hope someone can clarify this wink (and I hope I put this thread in the right forum).

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 10-Aug-2007 14:10:46   

These are id's generated by ASP.NET. In the HTML code, we given them id's like tbxSearchString and asp.net creates the other id's from it. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
Melp
User
Posts: 2
Joined: 10-Aug-2007
# Posted on: 10-Aug-2007 14:24:35   

I know (no .net newbie wink ), but apparently with HnD ASP.Net does not create the id's. They id's in the HTML sent to the web browser are the same as in the ASPX-source code. Do a "View source" on the search page for example, and you'll see that the id's of the controls there are untouched by ASP.Net. (I hope I explained it clearly what I mean simple_smile )

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39749
Joined: 17-Aug-2003
# Posted on: 10-Aug-2007 15:56:05   

Melp wrote:

I know (no .net newbie wink ), but apparently with HnD ASP.Net does not create the id's. They id's in the HTML sent to the web browser are the same as in the ASPX-source code. Do a "View source" on the search page for example, and you'll see that the id's of the controls there are untouched by ASP.Net. (I hope I explained it clearly what I mean simple_smile )

I don't really follow what you mean simple_smile . When I click view source on this message page I see, for example plPageListTop_rptPageListMessages_ctl01_lblMessagesPage, which is a label, in the rptPageListMessages repeater which is inside the plPageListTop control instance.

So I think it is happening when the control is inside another control. THEN it will get a wacky id, otherwise it keeps it's id. This is necessary as you otherwise will get twice the same id on the page if you place the same control multiple times on your page. simple_smile

Frans Bouma | Lead developer LLBLGen Pro
jmeckley
User
Posts: 403
Joined: 05-Jul-2006
# Posted on: 10-Aug-2007 18:11:57   

if a control is nested within another control (like ascx, gridview rows, formview items repeater items, master pages.

asp.net appends the names of parent controls to the child control. As Otis stated, this ensures unique ids on the client, which is required. so if you have a simple WebForm1.aspx

<asp:Label id="MyLabel" />
<asp:TextBox id="MyTextBox" />

the server ids will match the client ids

however if you have a WebControl.ascx

<asp:Label id="MyLabel" />
<asp:TextBox id="MyTextBox" />

and you place this on WebForm1.aspx

<my:WebControl id="MyWebControl" />

your client ids will look something like this MyWebControl_MyLabel MyWebControl_MyTextBox

if you have a gridview on the webform

<asp:GridView id="MyGridView">
   <Columns>
      <asp:TemplateField>
         <asp:Label id="MyLabel" />
      </asp:TemplateField>
   </Columns>
</asp:GridView>

the id for the label would look like this MyGridView_ctrl0_MyLabel MyGridView_ctrl1_MyLabel MyGridView_ctrl[N]_MyLabel where [N] is the row index.

this would allow you to place a web user control the the same page multiple times.