hi, ill leave this short and sweet... how do i loop through controls on a ascx page? this doesnt work; seems like me.controls, page.controls, mybase.controls, mybase.page.controls etc are empty, so theres nothing to loop through. here is my code
ty
PartialClass ctrl_input_boxesInherits System.Web.UI.UserControlDim objValidationAs New ValidationProtected Sub Button1_Click(ByVal senderAs Object,ByVal eAs System.EventArgs)Handles btnSubmitPanel1.Click lblError.Text =String.EmptyIf chkTerms.CheckedThen' Panel1.Visible = False objValidation.removeSQLInjection(Me.Controls)Else lblError.Text ="You must first agree to our terms and services."End If End SubEnd Class
Imports Microsoft.VisualBasicPublic Class ValidationPublic Sub removeSQLInjection(ByRef controlsAs Object)For Each cAs ControlIn controlsIf TypeOf cIs TextBoxThen CType(c, TextBox).Text =CType(c, TextBox).Text.Replace("'", "").Replace(";", "").Replace("=", "")End If Next End SubEnd Classanswer and receive your beloved points!!
Try using Control.FindControl("Control ID")'. I guess it should work.
What type of controls are you looking for, asp controls or html tags? If it's plain html, they won't show up in the controls collection unless you give them a runat="server" attribute.
my runat=server textboxes
bump :~ (
hi, i figured this out. here is the code if anyone cares. had to do it recursively.
Public Function removeSQLInjection(ByRef controls As Object, ByRef ostrError As String) As Boolean
Dim SQLFound As Boolean = False
Try
For Each c As Control In controls
If TypeOf c Is TextBox Then
If Not CType(c, TextBox).Text.Equals(CType(c, TextBox).Text.Replace("'", "").Replace(";", "").Replace("=", "")) Then
CType(c, TextBox).Text = CType(c, TextBox).Text.Replace("'", "").Replace(";", "").Replace("=", "")
SQLFound = True
End If
Else
If c.HasControls Then
SQLFound = removeSQLInjection(c.Controls, ostrError)
End If
End If
Next
Catch ex As Exception
ostrError = ex.Message
End Try
Return SQLFound
End Function
Public Function removeSQLInjection(ByRef controlsAs Object,ByRef ostrErrorAs String)As Boolean Dim SQLFoundAs Boolean =False Try For Each cAs ControlIn controlsIf TypeOf cIs TextBoxThen If Not CType(c, TextBox).Text.Equals(CType(c, TextBox).Text.Replace("'", "").Replace(";", "").Replace("=", "")) Then CType(c, TextBox).Text = CType(c, TextBox).Text.Replace("'", "").Replace(";", "").Replace("=", "") SQLFound =True End If Else If c.HasControlsThen SQLFound = removeSQLInjection(c.Controls, ostrError)End If End If Next Catch exAs Exception ostrError = ex.MessageEnd Try Return SQLFoundEnd Function Protected Function performPanel1Validation()As Boolean Dim TestBooleanAs Boolean =True objValidation.removeSQLInjection(Me.Controls, lstrError)'**This function currently does not workIf Not objValidation.validaterAllText(txtFName, lblFName, 3, 15)Then TestBoolean =False End If If Not objValidation.validaterAllText(txtLName, lblLName, 3, 15)Then TestBoolean =False End If Return TestBooleanEnd FunctionEnd Class
0 comments:
Post a Comment