Using a 404 in this situation would break http standards. As suggested in the comments simply code for the situation where the page is accessed directly.
Have an error message in an asp:Literal on the page with Visible=false then in your code behind;
If Not dataFound Then
LiteralMyError.Visible = True
Exit ' not sure if this is how you abort a function, I dont know vb.net
End If