当前位置: 移动技术网 > IT编程>开发语言>.net > 详解Asp.Net母版页元素ID不一致的体现

详解Asp.Net母版页元素ID不一致的体现

2018年11月30日  | 移动技术网IT编程  | 我要评论

月上重火19楼,www.4567.tv,马子越

本文介绍了asp.net母版页元素id不一致的体现,分享给大家,具体如下;

<%@ page language="c#" masterpagefile="~/masterpage.master" theme="style" autoeventwireup="true"
   codefile="r_balance.aspx.cs" inherits="report_r_balance" %>

<asp:content id="content" contentplaceholderid="maincontent" runat="server">

 

   <form id="form1" runat="server">
     <div>
       <table cellspacing="0" cellpadding="0" border="0">
         <tbody>
           <tr>
             <td>
               <asp:label id="lbpagename" runat="server" skinid=" " text="余额统计"></asp:label>
             </td>
           </tr>
           <tr>
             <td>
               <asp:imagebutton id="btnprint" runat="server" skinid="b_print" ="btnprint_click" />
               <asp:imagebutton id="btnexport" runat="server" skinid="b_export" ="btnexport_click" />
             </td>
           </tr>
         </tbody>
       </table>
       <!--结束功能条-->
       <table border="1" style="font: 宋体; font-size: 12px;">
         <tr>
                   <td style="width: 256px; height: 15px;">
             卡号*</td>
           <td colspan="1" style="width: 233px; height: 15px">
             <asp:textbox id="txtc_printno" runat="server"></asp:textbox></td>
           <td colspan="1" style="height: 24px; font-size: 14px; font-family: 宋体; width: 180px;"
            >
             <asp:imagebutton id="nsearch" runat="server" alternatetext="查询" imagealign="middle"
               imageurl="~/images/go.gif" ="nsearch_click" />
           </td>
         </tr>
       </table>

....

生成的html代码:

  <form name="aspnetform" method="post" action="r_balance.aspx" id="aspnetform">

<table cellspacing="0" cellpadding="0" border="0">
         <tbody>
           <tr>
             <td>
               <span id="ctl00_maincontent_lbpagename" style="display:inline-block;color:#f2f3f9;border-style:none;font-family:宋体;font-size:13px;height:22px;">余额统计</span>
             </td>
           </tr>
           <tr>
             <td>
               <input type="image" name="ctl00$maincontent$btnprint" id="ctl00_maincontent_btnprint" src="../app_themes/style/images/b_print.jpg" ="return np();" style="border-style:ridge;border-width:0px;" />
               <input type="image" name="ctl00$maincontent$btnexport" id="ctl00_maincontent_btnexport" src="../app_themes/style/images/b_export.jpg" style="border-style:ridge;border-width:0px;" />
             </td>
           </tr>
         </tbody>
       </table>
       <!--结束功能条-->
       <table border="1" style="font: 宋体; font-size: 12px;">
         <tr>

           <td style="width: 256px; height: 15px;">
             卡号*</td>
           <td colspan="1" style="width: 233px; height: 15px">
             <input name="ctl00$maincontent$txtc_printno" type="text" id="ctl00_maincontent_txtc_printno" style="width:120px;height:16px;font-size:12px;font-family:宋体;color:dimgray;border-width:1px;border-style:solid;border-color:#c4cae6;background-color:white;" /></td>
           <td colspan="1" style="height: 24px; font-size: 14px; font-family: 宋体; width: 180px;"
            >
             <input type="image" name="ctl00$maincontent$nsearch" id="ctl00_maincontent_nsearch" src="../images/go.gif" alt="查询" ="return nselect();" style="border-width:0px;" />
           </td>
         </tr>
       </table>

注意:

1.源文件控件和元素id和生成html文件的id不一致。在生成的html中原asp控件id加了ctl00_maincontent_前缀,其他元素加了ctl00$maincontent$前缀。原变form1为aspnetform这是因为aspx页面的控件是母板页的contentplaceholder
控件下的子控件,所以控件id会变

2.<system.web><xhtmlconformance mode="transitional|legacy|strict" />在其中选择 transitional、strict则产生自动前缀。ctl00.选择 legacy|则产生自动前缀_ctl0.

3.后台request.form["txtc_name"]键值需要改变,必须变为request.form["ctl00$maincontent$txtc_name"]才能收到页面输入值

4.至于为什么,只能说这是.net机制问题。。。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网