Logo 
Search:

Asp.net Forum

Ask Question   UnAnswered
Home » Forum » Asp.net       RSS Feeds

Shorter Version of Validator Problem

  Asked By: Molly    Date: Jul 04    Category: Asp.net    Views: 7241
  

friends this is the probelm I had posted yesterday but
then The Code was
too big and So I have made a shorter version of that
By Dynamically creating
the textboxes.Tell me how to Add the
RequiredFieldValidator to this Programme

Here the Code


Public Class DynamicValidator
Inherits System.Web.UI.Page
Protected WithEvents btn_validate As
System.Web.UI.WebControls.Button
Protected WithEvents dynTable1 As
System.Web.UI.WebControls.Table

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private
Sub InitializeComponent()

End Sub

Private Sub Page_Init(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Init
'CODEGEN: This method call is required by the
Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Private Sub Page_Load(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
MyBase.Load
Dim Cntr As Integer
For Cntr = 1 To 3
Dim tr As New TableRow()
Dim tc As New TableCell()
Dim txt As New TextBox()

txt.ID = "Text" & CStr(Cntr)
txt.Text = ""

Dim txtValid As RequiredFieldValidator =
New RequiredFieldValidator()
txtValid.ControlToValidate = txt.ID
txtValid.ErrorMessage = "Fields Cannot be
Blank"
txtValid.Display =
ValidatorDisplay.Dynamic

tc.Text = " Choice" & Cntr & " : "

tc.Font.Name = "Verdana"
tc.Font.Size = New
System.Web.UI.WebControls.FontUnit(10)

tr.Cells.Add(tc)

tc = New TableCell()
tc.Controls.Add(txt)
tr.Cells.Add(tc)

dynTable1.Rows.Add(tr)
Next
End Sub

Private Sub btn_validate_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
btn_validate.Click
If IsValid = True Then
Response.Write("Page valid")
Else
Response.Write("Page Isnt Valid")
End If

End Sub
End Class

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Hayden Evans     Answered On: Jul 04

You forgot ta add  the validator  control to your cell:
tc.Controls.Add(txtValid)

 
Didn't find what you were looking for? Find more on Shorter Version of Validator Problem Or get search suggestion and latest updates.




Tagged: