469,951 Members | 2,295 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,951 developers. It's quick & easy.

Using Validation Controls with Page.ParseControl


I'm playing around with the possibilities of Page.ParseControl.

Thanks to Kirk Allen Evans I got my example running
(Posting Juli, 17, "Re: Generating ASP.NET-Controls with XSLT possible?").
But looking deeper I run into a problem:

Kirk said, that "validation works as expected", but in my experience it
works only to a certain degree "as expected".

I test the server-side validation and disable JavaScript.
Now I get this scenario:

- When you enter a name, no warning appears, that's good!
- When you don't enter a name, the warning appears, that's very good!
So everything seems to be right.

But what, if you get the idea to check in your code, whether the form is
valid or not, perhaps this way:

---parsetest.aspx--- --- --- --- --- --- --- --- --- --- --- --- --- --- ---
--- --- --- ---
<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="parsetest.aspx.vb" Inherits="Xorum.parsetest" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema"
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<p runat="server" id="kommentar" ></p>
parsetest.aspx.vb --- --- --- --- --- --- --- --- --- --- --- --- --- --- --
- --- ---
Public Class parsetest
Inherits System.Web.UI.Page
Protected form1 As System.Web.UI.HtmlControls.HtmlForm
Protected kommentar As System.Web.UI.HtmlControls.HtmlGenericControl

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim s As String
s = "What is your name? <br><br><input runat='server' id='txtName'
type='text' ><asp:RequiredFieldValidator id='reqTxtName'
ControlToValidate='txtName' Display='dynamic' runat='server'>
Please enter your name.</asp:RequiredFieldValidator> <br><br><input
runat='server' type='submit' value=' OK ' ><br><br><asp:Label id='meldung'
runat='server' />"

If IsPostBack Then
If Page.IsValid Then
kommentar.InnerHtml &= "OK "
kommentar.InnerHtml &= "Not OK "
End If
End If
End Sub
End Class
--- --- --- --- --- --- --- --- --- --- --- --- --- --- --- --- ---

This is the result:

The validation works correctly, but using "Page.IsValid" will ALWAYS return
false. Even if the
validation control works correctly and no warning appears, there will be the
message "Not OK "!!!

On the other side: When I use just this code, but don't use
Page.ParseControl, but
insert the code for the form and the validation-control right into the
aspx-Page, everything works
fine and Page.IsValid will always say correctly, whether the form is valid
or not.

Any idea?

Thank you


Nov 11 '05 #1
0 2119

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Matthias Lohrer | last post: by
4 posts views Thread by Kevin Phifer | last post: by
2 posts views Thread by anthonykallay | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.