dynamic form not validating on server

  • Thread starter Thread starter Guest
  • Start date Start date
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
 
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.
 
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
 
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.
 
Back
Top