dynamic form not validating on server

G

Guest

Hello,

I am trying to create a form dynamically. A very simple form with a textbox,
requiredvalidator and button.

Everything works fine on IE, but no server side validation occurs which
means the requiredfieldvalidator is ignored when using Netscape.

The code logic is:

'Declare a an html form i.e
Dim objForm As New HtmlForm
objForm.Attributes.Add("RunAt", "Server")

Create a table, tablerow and tablecell

Add a textbox and requirefieldvalidator to a cell
Add the cell to the row
Add the row to the table
Add a button to the table
Add the table to the form
Add the form to a placeholder control on the web page

Is there something I am missing? I tried adding the requiredfieldvalidator
control to the validators collection of the page, ie
Me.Validators.Add(validatorcontrol)
as described in http://forums.asp.net/577243/ShowPost.aspx but that makes no
difference.

I have switched off clientside validation and get the same result in IE.

Is there something simple I am missing or do I really need to take a serious
look at creating user controls in asp.net?

Best Regards,

Steve Bugden
 
G

Guest

At which stage of the page's lifecycle are you adding your form? Dynamically
added controls need to be added during the Page.Init stage to maintian their
ViewState upon postback.
 
G

Guest

Hi Phillip,

Thanks for the reply.

I moved the dynamically added controls from teh page_load event to the
Page_Init event and it now works fine. ie the requiredfieldvvalidator kicks
in if a required field is missing.

But I would also like to display a simple user message (rather than the
form), if the form is valid. On the postback, in the Page_Init event after
calling Me.Page.Validate, Me.Page.IsValid is set true, (Although this works
correctly in the page_load event)

How can I stop the form displaying if the it is valid?

Best Regards,

Steve
 
G

Guest

Hi Phillip,

Sorry for such a stupid question, I just cleared the placeholder in the
page_load event if the form is valid.

Thanks once again for you help,

Steve Bugden.
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top