Posted By

MSISnippets on 05/08/12


Tagged


Versions (?)

Querystring Validation


 / Published in: VB.NET
 

  1. Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
  2. ' Validate Querystrings
  3. ' Set raw querystring values to local variables, by definition,
  4. ' these are strings.
  5. Dim RawSubjectID As String = Request.QueryString("SubjectID")
  6. Dim RawGroupID As String = Request.QueryString("GroupID")
  7. Dim RawTypeID As String = Request.QueryString("TypeID")
  8.  
  9. ' Check for empty string values (querystring value not passed) and
  10. ' validate the expected data type:
  11. ' Array: IsArray(<obj to validate>)
  12. ' Date: IsDate(<obj to validate>)
  13. ' Integer: Int32.TryParse(<value to parse>, <variable to set if successful)
  14. '
  15. If (Not String.IsNullOrEmpty(RawSubjectID) And Int32.TryParse(RawSubjectID, SubjectID)) And _
  16. (Not String.IsNullOrEmpty(RawGroupID) And Int32.TryParse(RawGroupID, GroupID)) And _
  17. (Not String.IsNullOrEmpty(RawSubjectID) And Int32.TryParse(RawTypeID, TypeID)) Then
  18.  
  19. ' Querysting validated, add code here...
  20.  
  21. End If
  22. End Sub

Report this snippet  

You need to login to post a comment.