How to change default form name "aspnetForm" in Beta 2
2010-06-13 18:11
751 查看
/* from: http://www.cnblogs.com/payne/archive/2007/04/30/733328.html */
Here's the responsible code for that error:
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).
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"; } } } } |
相关文章推荐
- How to change default form name "aspnetForm" in Beta 2
- 消除 ASP.NET Core 告警 "No XML encryptor configured. Key may be persisted to storage in unencrypted form"
- zhuanzai: AJAX: How to create a "Processing" modal window using UpdateProgress and ModalPopup ASP.net AJAX controls
- How to use Asp.Net Mvc ActionFilterAttribute for form authentication
- how to use Form Authentication in ASP.NET.
- How to set the DefaultButton in a Page Based on ASP.NET Master Page
- How to programmatically change the default view of an InfoPath form
- How to get the Current Controller Name, Action, or ID in ASP.NET MVC
- How to Turn Off / Disable AutoComplete – ASP .Net
- How to set window title name on Oracle EBS Form?
- How to debug asp.net mvc 4 source code?如何调试asp.net mvc4 源代码?
- Ubuntu: How to Change the Computer Name
- How To Debug an ASP.NET Web Application
- How to fix intellisense issues after upgrading to ASP.NET Ajax 1.0 RC
- ASP.NET MVC Toolkit - how to use the Html Helper class
- [转]How to override HandleUnauthorizedRequest in ASP.NET Core
- How to build an Expression builder for ASP.Net 2.0
- HTMLEditor Provider - How to write a custom provider for ASP.NET 2.0
- How to change Visual Studio default environment setting
- How to prevent multiple clicks of a submit button in ASP.NET