Mittwoch, 21. Dezember 2011

Error when placing a TextBox inside a LayoutsPageBase

I was developing an application page that inherits from the LayoutsPageBase. 
In this page I added a user Control in which I added A TextField and a Button. Here is the code for that part:

<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ExportApplicationSettingsUserControl.ascx.cs" Inherits="ListItemExport.ControlTemplates.ListItemExport.ExportApplicationSettingsUserControl" %>
<asp:TextBox ID="exportTemplate" runat="server"></asp:TextBox>
<br />
<asp:Button ID="saveButton" runat="server" onclick="saveButton_Click" Text="Button" />

When Executing this code I got following error message:

Control 'ctl01_exportTemplate' of type 'TextBox' must be placed inside a form tag with runat=server.

So I added the form tag around my form elements like this:

<form id="myForm" runat=server></form>
<asp:TextBox ID="exportTemplate" runat="server"></asp:TextBox>
<br />
<asp:Button ID="saveButton" runat="server" onclick="saveButton_Click" Text="Button" />
</form>

This time a got following error message:

A page can have only one server-side Form tag.

It came out that the masterpage already had a form tag. I tried to delete the form tag from the masterpage or to include other masterpage, but nothing helped. There were always new errors appearing.
Finally I found the solution for my problem. It appeared that this was simply a bug. The solution was to add following empty method to the application page code behind:


public override void VerifyRenderingInServerForm(Control control){}

Don’t forget to delete the added form tag in the application page. And don’t make any changes on the masterpage.
This solved the problem. Thanks to this Post 

Keine Kommentare:

Kommentar veröffentlichen