When the Html text of a control is output in MasterPage, the "XX" control of the "XX" type must be placed in the form tag with runat = server "problem is solved.

Source: Internet
Author: User
Error Code
Master. Master slave ---------------------------------------------------------------------------------------------
<% @ Master Language = "C #" AutoEventWireup = "true" CodeFile = "master. master. cs"
Inherits = "master_master" %>
<! 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> test </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Asp: ContentPlaceHolder ID = "ContentPlaceHolder1" runat = "server">
</Asp: ContentPlaceHolder>
</Form>
</Body>
</Html>

InMasterPage. aspx plugin ---------------------------------------------------------------------------------------

<% @ Page Language = "C #" MasterPageFile = "~ /Master. master "AutoEventWireup =" true"
CodeFile = "Order. aspx. cs" Inherits = "InMasterPage_Order" %>

<Asp: Content ID = "Content1" ContentPlaceHolderID = "ContentPlaceHolder1" runat = "Server">
<Table cellpadding = "0" cellspacing = "0" border = "0" width = "100%">
<Tr align = "left" valign = "top">
<Td style = "width: 40%;">
<Asp: SqlDataSource ID = "SqlDataSourceTicketInfo" runat = "server" ConnectionString = "<% $ ConnectionStrings: YinYeTravelConnectionString %>"
SelectCommand = "* WHERE ([OperationID] = @ OperationID)">
<SelectParameters>
<Asp: QueryStringParameter Name = "OperationID" QueryStringField = "ID" Type = "Int32"/>
</SelectParameters>
</Asp: SqlDataSource>
<Div id = "OrderInfo" runat = "server">
<Asp: DetailsView ID = "DetailsView1" runat = "server" AutoGenerateRows = "False" BackColor = "White"
BorderColor = "#336666" BorderStyle = "Double" BorderWidth = "3px" CellPadding = "4"
DataKeyNames = "OperationID" DataSourceID = "SqlDataSourceTicketInfo" GridLines = "Horizontal"
HeaderText = "**" HorizontalAlign = "Center" Width = "300px">
<FooterStyle BackColor = "White" ForeColor = "#333333"/>
<EditRowStyle BackColor = "#339966" Font-Bold = "True" ForeColor = "White"/>
<RowStyle BackColor = "White" ForeColor = "#333333"/>
<PagerStyle BackColor = "#336666" ForeColor = "White" HorizontalAlign = "Center"/>
<Fields>
<Asp: BoundField DataField = "OperationID" HeaderText = "OperationID" InsertVisible = "False"
ReadOnly = "True" SortExpression = "OperationID"/>
<Asp: BoundField [other bindings, Here omitted]/>
</Fields>
<HeaderStyle BackColor = "#00C000" Font-Bold = "True" ForeColor = "White"/>
</Asp: DetailsView>
</Div>
</Td>
<Td style = "width: 60%;">
</Td>
</Tr>
</Table>
</Asp: Content>

InMasterPage. aspx. cs -------------------------------------------------------------------------------

System. IO. StringWriter sw = new System. IO. StringWriter ();
HtmlTextWriter htw = new HtmlTextWriter (sw );
DetailsView1.RenderControl (htw );

The error message "XX" indicates that the control "XX" of "type" XX "must be placed in the form tag with runat = server"

I have encountered this problem before, probably because my control is no longer in the Form label. But here we are.
Well, I cannot explain it clearly.

So I found Msdn to see which method is reporting an error, and finally found the VerifyRenderingInServerForm method. Fortunately, this method supports rewriting, so I added it to the page with a try attitude.
Public override void VerifyRenderingInServerForm (Control control Control)
{
// Base. VerifyRenderingInServerForm (control );
}

Test passed. I don't know why.
It seems that there is no reason, but this can only be done for the time being. You can check it out later!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.