By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,136 Members | 1,212 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,136 IT Pros & Developers. It's quick & easy.

Validation is not working when form tag is declared dynamically

P: n/a
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>
&nbsp;
<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>
Nov 18 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Does the <form> tag need the attribute runat="server"?
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.