Control 'Contentplaceholder1_name' of type 'Textbox' must be inserted in a format tag with runat=server

Asked

Viewed 746 times

0

I’m doing a job for the college, a Forms web application on Asp.net C#. I have a problem and until then everything was going well, but suddenly it is giving this mistake. I searched some related things, and this excerpt ended up "showing" my web page, but does not perform any action:

public override void VerifyRenderingInServerForm(Control control){ }

Error and exceptions:

Control 'Contentplaceholder1_name' of type 'Textbox' must be inserted in a format tag with runat=server.

Description: An untreated exception occurred during the execution of the current web request. Examine stack tracking for more information about the error and where it originated in the code.

Exception Details: System.Web.Httpexception: 'Contentplaceholder1_name' control of type 'Textbox' must be inserted in a format tag with runat=server.

Cell Trace:

[httpexception (0x80004005): 'Contentplaceholder1_name' control of type 'Textbox' must be inserted in a format tag with runat=server. ] System.Web.UI.Page.Verifyrenderinginserverform(Control control) +9766490 System.Web.UI.WebControls.Textbox.Addattributestorender(Htmltextwriter Writer) +52 System.Web.UI.WebControls.Webcontrol.Renderbegintag(Htmltextwriter Writer) +20 System.Web.UI.WebControls.Textbox.Render(Htmltextwriter Writer) +21 System.Web.UI.Control.Rendercontrolinternal(Htmltextwriter Writer, Controlpter Adapter) +66 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer, Controlpter Adapter) +100 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer) +25 System.Web.UI.Control.Renderchildreninternal(Htmltextwriter Writer, Icollection Children) +128 System.Web.UI.Control.Renderchildren(Htmltextwriter Writer) +13 System.Web.UI.Control.Render(Htmltextwriter Writer) +12 System.Web.UI.Control.Rendercontrolinternal(Htmltextwriter Writer, Controlpter Adapter) +66 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer, Controlpter Adapter) +100 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer) +25 System.Web.UI.Control.Renderchildreninternal(Htmltextwriter Writer, Icollection Children) +128 System.Web.UI.Control.Renderchildren(Htmltextwriter Writer) +13 System.Web.UI.Control.Render(Htmltextwriter Writer) +12 System.Web.UI.Control.Rendercontrolinternal(Htmltextwriter Writer, Controlpter Adapter) +66 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer, Controlpter Adapter) +100 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer) +25 System.Web.UI.Control.Renderchildreninternal(Htmltextwriter Writer, Icollection Children) +128 System.Web.UI.Control.Renderchildren(Htmltextwriter Writer) +13 System.Web.UI.Page.Render(Htmltextwriter Writer) +29 System.Web.UI.Control.Rendercontrolinternal(Htmltextwriter Writer, Controlpter Adapter) +66 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer, Controlpter Adapter) +100 System.Web.UI.Control.Rendercontrol(Htmltextwriter Writer) +25 System.Web.UI.Page.Processrequestmain(Boolean includedStagesBeforeAsyncPoint, Boolean includedStagesAfterAsyncPoint) +1303

Code of my Login.aspx

<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Login_Login" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
        <div class="panel panel-default" style="width: 450px; margin: 50px 50px 50px 600px; -webkit-box-shadow: 11px 10px 65px -4px rgba(0,0,0,0.59); -moz-box-shadow: 11px 10px 65px -4px rgba(0,0,0,0.59); box-shadow: 11px 10px 65px -4px rgba(0,0,0,0.59);">
            <div class="panel-heading" style="text-align: center;">
                <h1 style="font-weight: bold;">ENTRAR</h1>
            </div>
            <div class="panel-body" style="margin: 20px 50px 20px 100px;">
                <p><span style="font-weight: bold">NOME</span></p>
                <asp:TextBox ID="Nome" Width="200px" runat="server" CssClass="form-control" placeholder="Login" aria-describedby="basic-addon1"></asp:TextBox>
                <span style="margin: 400px;"></span>
                <p>
                    <span style="font-weight: bold">SENHA</span><br />
                    <asp:TextBox ID="Senha" Width="200px" TextMode="Password" runat="server" CssClass="form-control" placeholder="Senha" aria-describedby="basic-addon1"></asp:TextBox>
                </p>
                <asp:Button ID="Entrar" runat="server" OnClick="Entrar_Click" Text="Entrar" CssClass="btn btn-primary btn-success" />
            </div>

        </div>
        <div style="text-align: center;">
            <span style="margin: 50px;">
                <asp:Label ID="Mensagem" runat="server" Visible="false" CssClass="alert alert-danger" role="alert"></asp:Label>
            </span>
        </div>
</asp:Content>

Login.aspx.Cs

public partial class Login_Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {

        }
    }


    protected string conn = @"Data Source=PC-OSV;Initial Catalog=CadastroCompetencias;Integrated Security=True;";
    AppDatabase.SqlServerTransaction db = new AppDatabase.SqlServerTransaction();

    protected void Entrar_Click(object sender, EventArgs e)
    {
        if (ValidaUsuario(Nome.Text, Senha.Text))
        {
            // Inicializa a classe de autenticação do usuário
            FormsAuthentication.Initialize();
            //Define os dados do ticket de autenticação 
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, Nome.Text, DateTime.Now, DateTime.Now.AddMinutes(30), false, Session["Perfil"].ToString(), FormsAuthentication.FormsCookiePath);
            // Grava o ticket no cookie de autenticação
            Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
                 FormsAuthentication.Encrypt(ticket)));
            // Redireciona para a página do usuário
            Response.Redirect(FormsAuthentication.GetRedirectUrl(Nome.Text, false));
        }
        else
        {
            Mensagem.Visible = true;
            Mensagem.Text = "Oops... Login ou senha errados! Verifique se você não errou nada.";
        }
    }

    /// <summary>
    /// Autentica o usuário e retorna true se foi autenticado com sucesso
    /// </summary>
    protected bool ValidaUsuario(string nome, string senha)
    {
        db.ConnectionString = conn;
        DataTable tb = (DataTable)db.Query("SELECT * FROM Usuarios WHERE NomeAcesso='" + Nome.Text + "' AND Senha='" + Senha.Text + "' AND Estatus=1;");
        if (tb.Rows.Count == 1)
        {
            // Armazena na dados do usuário nas variáveis de sessão 
            Session["CodigoUsuario"] = tb.Rows[0]["CodigoUsuario"];
            Session["NomeUsuario"] = tb.Rows[0]["NomeCompleto"];
            Session["Perfil"] = "Administrador";
            return true;
        }
        else
        {
            return false;
        }
    }

}

I count on your collaboration! Thank you from now on!

  • Try to house the content of your page with a tag <form runat="server">

  • So Eric, I already have on my Masterpage a form containing runat="server"

1 answer

1

I found the personal answer! In my case, the tag </form> was in the wrong place, I ended up closing it at the end of my content, which in my case, at Masterpage, I have a <footer></footer>. And now it’s all working properly!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.