ASP.net 2.0 and 1.1 differ in the content of the generated foreground page.

Source: Internet
Author: User
Tags html tags
Asp.net| page

I stumbled upon a difference between 2.0 and 1.1 and wrote it out to give you a wake-up call.
is about the foreground page to generate the code. As we know, ASP.net's server controls eventually explain the JavaScript footsteps and HTML code in the foreground, such as the "DataGrid" control is interpreted as a "table" tab, and the CheckBox control is interpreted as "<input type=" CheckBox ' ... ' label. Both asp.net2.0 and asp.net1.1 are such mechanisms, so we can often use this mechanism to write JavaScript scripts in the foreground to manipulate the HTML tags generated by these explanations, and to invoke some events. I do not know whether people often use this, anyway, I often use this method, and enjoy.
An accidental incident found a problem, I directly copied some of the 1.1 under the JS script to 2.0 under the use of the project, found that there are errors, script errors, baffled, and then carefully studied the asp.net2.0 generated foreground code, found the secret. Under ASP.net, after the server control in the DataGrid template column is interpreted, the resulting label generates a new ID based on the ID of the original server control.
For example (asp.net1.1), the CheckBox control is used in the template column of the DataGrid control:

<asp:datagrid id= "Mydatagrid" runat= "Server" autogeneratecolumns= "False" height= "100%" width= "100%"
Enableviewstate= "false" >
<alternatingitemstyle cssclass= "List_bai" ></AlternatingItemStyle>
<itemstyle cssclass= "List_lan" ></ItemStyle>
<Columns>
<asp:boundcolumn datafield= "color_id" headerstyle-cssclass= "distd" itemstyle-cssclass= "DisTd" ></asp: Boundcolumn>
<asp:templatecolumn headerstyle-horizontalalign= "center" itemstyle-horizontalalign= "center" HeaderText= "Choice < Input type= ' checkbox ' id= ' > ' >
<itemstyle horizontalalign= "Center" cssclass= "LIST_TD" ></ItemStyle>
<ItemTemplate>
<asp:checkbox id= "CheckBox1" runat= "Server" ></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
<asp:hyperlinkcolumn datanavigateurlfield= "color_id" datanavigateurlformatstring= "InfoCOLOR.aspx?id={0}& Flag=0 "
Datatextfield= "Color_name" headertext= "color name" >
<itemstyle horizontalalign= "Center" cssclass= "LIST_TD" ></ItemStyle>
</asp:HyperLinkColumn>
<asp:boundcolumn datafield= "Color_code" headertext= "Color HTML Encoding" >
<itemstyle horizontalalign= "Center" cssclass= "LIST_TD" ></ItemStyle>
</asp:BoundColumn>
</Columns>
</asp:datagrid>


explained to the foreground HTML later became:

<table cellspacing= "0" rules= "All" border= "id=" Mydatagrid "style=" Height:100%;width:100%;border-collapse: Collapse; " >
<tr class= "List_1" >
&LT;TD class= "DISTD" > </td>
&LT;TD class= "list_1" align= "Center" > select <input type= ' checkbox ' id= ' ></td>
&LT;TD class= "list_1" align= "Center" > Color name </td>
&LT;TD class= "list_1" align= "Center" > Color HTML encoding </td>
</tr>
<tr class= "List_lan" >
&LT;TD class= "DISTD" >16</td>
&LT;TD class= "List_td" align= "Center" > <input id= "mydatagrid__ctl2_checkbox1" type= "checkbox" Name= "Mydatagrid : _ctl2:checkbox1 "/></td>
&LT;TD class= "List_td" align= "Center" ><a href= "infocolor.aspx?id=16&flag=0" >213 "</a></td" >
&LT;TD class= "List_td" align= "Center" >123123</td>
</tr>
</table>
We can see that the DataGrid control becomes a table label, the ID is unchanged, and the original

<asp:checkbox id= "CheckBox1" runat= "Server" ></asp:CheckBox>
into a

<input id= "Mydatagrid__ctl2_checkbox1" type= "checkbox" Name= "Mydatagrid:_ctl2:checkbox1"/>
The "Mydatagrid__ctl2_checkbox1" here is asp.net automatically added, which is generated by combining the ID of his DataGrid with his ID and the row where the data is bound.
The above results are generated under the asp.net1.1, to the 2.0 generated ID changed, the ID is not mydatagrid__ctl2_checkbox1, but Mydatagrid:_ctl2:checkbox1, and the Name property is unchanged, It can be assumed that the purpose of Microsoft's doing so is to match ID with name, in fact it should be so, perhaps this is one of the dotnet1.1 unreasonable place.
Small discovery, hope to be helpful to everybody.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.