Using Validation Controls with Page.ParseControl

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default Using Validation Controls with Page.ParseControl

    Hi,

    I'm playing around with the possibilities of Page.ParseControl.
    I parse a string with an input-field and an RequiredFieldValidator-control.

    For testing the server-side validation I disable JavaScript
    and 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, by using "If Page.IsValid", 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">
    <html>
    <head>
    <title>parsetest</title>
    <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"
    content="http://schemas.microsoft.com/intellisense/ie5">
    </head>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    </form>
    <p runat="server" id="kommentar" ></p>
    </body>
    </html>


    --- ---
    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' />"
    form1.Controls.Add(Page.ParseControl(s))
    If IsPostBack Then
    Page.Validate()
    If Page.IsValid Then
    kommentar.InnerHtml &= "OK "
    Else
    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
    Matthias


    Matthias Lohrer Guest

  2. Similar Questions and Discussions

    1. Validation Between Controls
      I have a datagrid with several fields with textboxes and drop downs. I want to be able to validate the drop down field in one column to only be...
    2. Validation Controls
      Hello, I have placed many validation controls on an aspx webform and a user control that allows the visitor to enter a username and password and...
    3. Dynamic Controls using ParseControl
      Hello everybody, I am using xml and xslt to generate dynamic asp server controls on the page. What I do is I store the control type and their...
    4. Validation on custom controls
      Hi, I searched through NG's etc but could not find an answer to my problem..... I have a custom control that consists of 3 textboxes. I would...
    5. Page.ParseControl drives me crazy
      Hi, I want to add dynamically controls to my aspx-Page by using the Page.parseControl-method. Page_Load contains this code: str =...
  3. #2

    Default Re: Using Validation Controls with Page.ParseControl

    Hi
    Before calling page.IsValid, you should call Page.Validate

    Page.Validate
    Page.IsValid

    --


    Thank you.

    Satish Appasani
    #201, Wing - 1, Block - D
    Cyber Gateway
    Hyderabad - 500 081, India
    Phone: +91(40)2311-1356 Ext-122
    Mobile: +91(40)333-31032
    E-mail: [email]satish@vertexcs.com[/email]
    "Matthias Lohrer" <matthias.lohrer@mlohrer.de> wrote in message
    news:3f266355$0$258$4d4ebb8e@read.news.de.uu.net.. .
    > Hi,
    >
    > I'm playing around with the possibilities of Page.ParseControl.
    > I parse a string with an input-field and an
    RequiredFieldValidator-control.
    >
    > For testing the server-side validation I disable JavaScript
    > and 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, by using "If Page.IsValid", 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">
    > <html>
    > <head>
    > <title>parsetest</title>
    > <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"
    > content="http://schemas.microsoft.com/intellisense/ie5">
    > </head>
    > <body MS_POSITIONING="GridLayout">
    > <form id="Form1" method="post" runat="server">
    > </form>
    > <p runat="server" id="kommentar" ></p>
    > </body>
    > </html>
    >
    >
    > --- ---
    >
    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' />"
    > form1.Controls.Add(Page.ParseControl(s))
    > If IsPostBack Then
    > Page.Validate()
    > If Page.IsValid Then
    > kommentar.InnerHtml &= "OK "
    > Else
    > 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
    > Matthias
    >
    >

    Satish Appasani Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139