Querystring Validation

Submitted by:Andery Smith

Date added:15 May, 2012

Category:VB.NET

VB.NET Code example for querystring validation

Tags: querystring validation

Code Snippet:

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
' Validate Querystrings
' Set raw querystring values to local variables, by definition,
' these are strings.
Dim RawSubjectID As String = Request.QueryString("SubjectID")
Dim RawGroupID As String = Request.QueryString("GroupID")
Dim RawTypeID As String = Request.QueryString("TypeID")

' Check for empty string values (querystring value not passed) and
' validate the expected data type:
' Array: IsArray(<obj to validate>)
' Date: IsDate(<obj to validate>)
' Integer: Int32.TryParse(<value to parse>, <variable to set if successful)
'
If (Not String.IsNullOrEmpty(RawSubjectID) And Int32.TryParse(RawSubjectID, SubjectID)) And _
(Not String.IsNullOrEmpty(RawGroupID) And Int32.TryParse(RawGroupID, GroupID)) And _
(Not String.IsNullOrEmpty(RawSubjectID) And Int32.TryParse(RawTypeID, TypeID)) Then

' Querysting validated, add code here...

End If
End Sub
 
 

Comments