zoukankan      html  css  js  c++  java
  • How to change default form name "aspnetForm" in Beta 2

    Here's the responsible code for that error:

    public override string UniqueID
    {
          get
          {
                if (this.NamingContainer == this.Page)
                {
                      return base.UniqueID;
                }
                return "aspnetForm";
          }
    }
    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="TestBaseForm.aspx.cs" Inherits="TestBaseForm" %>

    <%@ Register TagPrefix="LA" Namespace="MyNamespace" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <LA:BaseForm runat="server" id="frmMain">
            <div>
            </div>
        </LA:BaseForm>
    </body>
    </html>

    --------------------------------------------------
    BaseForm.cs
    --------------------------------------------------
    using System;
    using System.Data;
    using System.Configuration;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;

    namespace MyNamespace
    {

        /// <summary>
        /// Summary description for BaseForm
        /// </summary>
        public class BaseForm : System.Web.UI.HtmlControls.HtmlForm
        {
            public BaseForm() : base() { }

            public override string UniqueID
            {
                get
                {
                    if(this.NamingContainer == this.Page)
                    { return base.UniqueID; }

                    return "frmMain";
                }
            }
        }
    }

    As you can see, when the naming container is different from the current page (something that happens when you use a master page) the UniqueID property return "aspnetForm". this property is rendered into the name attribute that is sent to the client in the form tag.  so, if you really need to, you can create your own form by inheriting from htmlform and then override the UniqueID property or the Name property (this may be a better option).

  • 相关阅读:
    POJ 1182 食物链(带权并查集)
    UVa 10655 n次方之和(矩阵快速幂)
    2016湘潭邀请赛—Heartstone
    2016湘潭邀请赛—Gambling
    UVa 10375 选择与除法(唯一分解定理)
    UVa 1637 纸牌游戏(全概率公式)
    POJ 2443 Set Operation(压位加速)
    UVa 11248 网络扩容(最大流(需要优化))
    51Nod 1737 配对(树的重心)
    51Nod 1070 Bash游戏 V4(斐波那契博弈)
  • 原文地址:https://www.cnblogs.com/payne/p/733328.html
Copyright © 2011-2022 走看看