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

A

André

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()
........
 
M

Milosz Skalecki [MCAD]

Hi Andre,

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

Regards
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top