I have a web form
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="test.aspx.vb" Inherits="test"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<body>
<form runat=server id =form1 >
<asp:Button id="btnSave" runat="server" CausesValidation= true Text="save"></asp:Button>
<asp:textbox id="txtAccountNumber" runat="server" Width="136px"></asp:textbox>
<asp:RequiredFieldValidator id="RequiredFieldValidator1" runat="server" ErrorMessage="RequiredFieldValidator"
ControlToValidate="txtAccountNumber">Enter Account Number</asp:RequiredFieldValidator>
</form>
</body>
</HTML>
When i click the btnSave button , if i dont have any value in txtAccountNumber ...it says 'Enter Account Number'
But IF I remove the <form runat=server> tag from html view and add the form tag dynamically in page load event... Validation doesn't work..
Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs) Handles MyBase.Load
Dim baseForm As HtmlForm
baseForm = New HtmlForm
baseForm.ID = "baseForm"
Me.Controls.Add(baseForm)
baseForm.Controls.Add(Me.btnSave)
baseForm.Controls.Add(Me.txtAccountNumber)
baseForm.Controls.Add(Me.RequiredFieldValidator1)
End Sub
When i view the source ...the btnSave doen't have the attribute the following attribute
onclick="if (typeof(Page_ClientValidate) == 'function') Page_ClientValidate(); "
Can you please tell me what causes the problem when the form is added dynamically and controls are moved to the form in form load event
( you may wonder..why i add the form tag dynamically...bcoz it is declared in my basepage...so the inheriting page's controls are moved the basepages form tag and my inheriting page should not have form tag)
-----------------------
Posted by a user from .NET 247 (http://www.dotnet247.com/)
<Id>rY7J2R08FUO4e0ijVIEQYw==</Id>