error "A form tag with runat=server must exist" but there is a form tag!!

Discussion in 'ASP .Net' started by André, Jun 22, 2008.

  1. André

    André Guest

    Hi,

    i get sometimes an very unexpected error:
    "A form tag with runat=server must exist on the Page to use SetFocus() or
    the Focus property"
    at line: If j = 1 Then txta(i).Focus()

    There is a form tag as you can see in the aspx file. Is there any other
    reason for this error?
    Thanks for help
    André


    The aspx code is this:

    <%@ Page Language="VB" MaintainScrollPositionOnPostback="true"
    AutoEventWireup="false" CodeFile="~/myfile.aspx.vb" Inherits="myfile" %>

    <!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>
    <form id="form1" runat="server">
    <div style="text-align: center">
    <asp:Label ID="Label1" runat="server" ></asp:Label>
    </div>
    <div style="text-align: center">
    <asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
    </div>
    </form>
    </body>
    </html>


    The code-behind:

    Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.PreInit
    ........
    txta(i) = New TextBox
    txta(i).TextMode = TextBoxMode.MultiLine
    frm.Controls.Add(txta(i))
    If j = 1 Then txta(i).Focus()
    ........
    André, Jun 22, 2008
    #1
    1. Advertising

  2. RE: error "A form tag with runat=server must exist" but there is a for

    Hi Andre,

    PreInit is too early to create controls, Use Page_Init event instead.

    Regards
    --
    Milosz


    "André" wrote:

    > Hi,
    >
    > i get sometimes an very unexpected error:
    > "A form tag with runat=server must exist on the Page to use SetFocus() or
    > the Focus property"
    > at line: If j = 1 Then txta(i).Focus()
    >
    > There is a form tag as you can see in the aspx file. Is there any other
    > reason for this error?
    > Thanks for help
    > André
    >
    >
    > The aspx code is this:
    >
    > <%@ Page Language="VB" MaintainScrollPositionOnPostback="true"
    > AutoEventWireup="false" CodeFile="~/myfile.aspx.vb" Inherits="myfile" %>
    >
    > <!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>
    > <form id="form1" runat="server">
    > <div style="text-align: center">
    > <asp:Label ID="Label1" runat="server" ></asp:Label>
    > </div>
    > <div style="text-align: center">
    > <asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
    > </div>
    > </form>
    > </body>
    > </html>
    >
    >
    > The code-behind:
    >
    > Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.PreInit
    > ........
    > txta(i) = New TextBox
    > txta(i).TextMode = TextBoxMode.MultiLine
    > frm.Controls.Add(txta(i))
    > If j = 1 Then txta(i).Focus()
    > ........
    >
    >
    >
    Milosz Skalecki [MCAD], Jun 22, 2008
    #2
    1. Advertising

  3. André

    André Guest

    Re: error "A form tag with runat=server must exist" but there is a for

    Thanks

    "Milosz Skalecki [MCAD]" <> schreef in bericht
    news:D...
    > Hi Andre,
    >
    > PreInit is too early to create controls, Use Page_Init event instead.
    >
    > Regards
    > --
    > Milosz
    >
    >
    > "André" wrote:
    >
    >> Hi,
    >>
    >> i get sometimes an very unexpected error:
    >> "A form tag with runat=server must exist on the Page to use SetFocus() or
    >> the Focus property"
    >> at line: If j = 1 Then txta(i).Focus()
    >>
    >> There is a form tag as you can see in the aspx file. Is there any other
    >> reason for this error?
    >> Thanks for help
    >> André
    >>
    >>
    >> The aspx code is this:
    >>
    >> <%@ Page Language="VB" MaintainScrollPositionOnPostback="true"
    >> AutoEventWireup="false" CodeFile="~/myfile.aspx.vb" Inherits="myfile" %>
    >>
    >> <!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>
    >> <form id="form1" runat="server">
    >> <div style="text-align: center">
    >> <asp:Label ID="Label1" runat="server" ></asp:Label>
    >> </div>
    >> <div style="text-align: center">
    >> <asp:Label ID="Label1" runat="server" Font-Bold="True"></asp:Label>
    >> </div>
    >> </form>
    >> </body>
    >> </html>
    >>
    >>
    >> The code-behind:
    >>
    >> Protected Sub Page_PreInit(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Me.PreInit
    >> ........
    >> txta(i) = New TextBox
    >> txta(i).TextMode = TextBoxMode.MultiLine
    >> frm.Controls.Add(txta(i))
    >> If j = 1 Then txta(i).Focus()
    >> ........
    >>
    >>
    >>
    André, Jun 23, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RC
    Replies:
    2
    Views:
    426
    Malte
    May 10, 2005
  2. shruds
    Replies:
    1
    Views:
    783
    John C. Bollinger
    Jan 27, 2006
  3. RC
    Replies:
    2
    Views:
    640
  4. mark4asp
    Replies:
    1
    Views:
    501
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Apr 3, 2007
  5. Marc Pichouron

    Search a keyword but but only on one kind of tag

    Marc Pichouron, Jan 8, 2004, in forum: Javascript
    Replies:
    0
    Views:
    96
    Marc Pichouron
    Jan 8, 2004
Loading...

Share This Page