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

发布时间:2022-04-16 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了详解Asp.Net母版页元素ID不一致的体现脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。

本文介绍了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机制问题。。。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本宝典。

脚本宝典总结

以上是脚本宝典为你收集整理的详解Asp.Net母版页元素ID不一致的体现全部内容,希望文章能够帮你解决详解Asp.Net母版页元素ID不一致的体现所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: