分享web开发知识

注册/登录|最近发布|今日推荐

主页 IT知识网页技术软件开发前端开发代码编程运营维护技术分享教程案例
当前位置:首页 > 运营维护

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

发布时间:2023-09-06 02:22责任编辑:沈小雨关键词:暂无标签

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

来自森大科技官方博客   http://www.cnsendblog.com/index.php/?p=104

<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" Theme="style" AutoEventWireup="true"
     CodeFile="r_Balance.aspx.cs"Inherits="Report_r_Balance" %>

<asp:ContentID="content" ContentPlaceHolderID="MainContent"runat="server">

  

    <form id="form1"runat="server">
         <div>
            <table class="topTable" cellspacing="0"cellpadding="0" border="0">
                <tbody>
                    <tr class="title">
                        <td>
                            <asp:Label ID="lbPagename"runat="server" SkinID="title" Text="余额统计"></asp:Label>
                        </td>
                    </tr>
                    <tr class="butt">
                        <td>
                            <asp:ImageButton ID="btnPrint"runat="server" SkinID="b_print"OnClick="btnPrint_Click" />
                            <asp:ImageButton ID="btnExport"runat="server" SkinID="b_export"OnClick="btnExport_Click" />
                        </td>
                    </tr>
                </tbody>
            </table>
            <!--结束功能条-->
            <table border="1" style="font: 宋体;font-size: 12px;">
                <tr>
                                    <td align="center" 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;"
                        align="center">
                        <asp:ImageButton ID="nSearch"runat="server" AlternateText="查询"ImageAlign="Middle"
                            ImageUrl="~/images/go.gif" OnClick="nSearch_Click" />
                    </td>
                </tr>
            </table>

....

生成的HTML代码:

   <formname="aspnetForm" method="post"action="r_Balance.aspx" id="aspnetForm">

<tableclass="topTable" cellspacing="0" cellpadding="0"border="0">
                <tbody>
                    <tr class="title">
                        <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 class="butt">
                        <td>
                            <input type="image" name="ctl00$MainContent$btnPrint"id="ctl00_MainContent_btnPrint"src="../App_Themes/style/images/b_print.jpg" align="middle"onclick="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"align="middle" style="border-style:Ridge;border-width:0px;"/>
                        </td>
                    </tr>
                </tbody>
            </table>
            <!--结束功能条-->
            <table border="1" style="font: 宋体;font-size: 12px;">
                <tr>

                    <td align="center" 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;"/></td>
                    <td colspan="1" style="height: 24px; font-size: 14px;font-family: 宋体; width: 180px;"
                        align="center">
                        <input type="image" name="ctl00$MainContent$nSearch"id="ctl00_MainContent_nSearch" src="../images/go.gif"alt="查询" align="middle"onclick="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><xhtmlConformancemode="Transitional|Legacy|Strict" />在其中选择Transitional、Strict则产生自动前缀。ctl00.选择 Legacy|则产生自动前缀_ctl0.

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

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

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

原文地址:https://www.cnblogs.com/cnsend/p/9955712.html

知识推荐

我的编程学习网——分享web前端后端开发技术知识。 垃圾信息处理邮箱 tousu563@163.com 网站地图
icp备案号 闽ICP备2023006418号-8 不良信息举报平台 互联网安全管理备案 Copyright 2023 www.wodecom.cn All Rights Reserved