0

I have a textbox for a zipcode in which i hav made a validation that the user cannot enter number less then or more then 6, but even if user enters 3 nos it is working.SO i want an error msg to display if user enters something wrong

Private Shared Function ValidateZip(ByVal pintZip As String, ByRef pobjErrMsg As Common.ErrorMessage) As Boolean
        If pintZip.Length <> 6 Then

        ElseIf IsNumeric(pintZip) Then

        End If

        Return True
End Function
Hoh
  • 1,196
  • 1
  • 12
  • 30
anuj
  • 429
  • 3
  • 7
  • 14

2 Answers2

0

You have no code in either the If or ElseIf blocks and you are always returning True

Martin Milan
  • 6,346
  • 2
  • 32
  • 44
  • i want to show an error to the user, then hw shud i achieve it – anuj Mar 31 '14 at 11:01
  • You might show an error using the MessageBox class, or you might produce a custom form to show the error... MessageBox is easiest, but won't look as good or be as flexible. Hoh's answer below looks good... – Martin Milan Apr 01 '14 at 08:11
0
Private Shared Function ValidateZip(ByVal pintZip As String, ByRef pobjErrMsg As Common.ErrorMessage) As Boolean
        If pintZip.Length <> 6 Then
          MsgBox("Zip code should have 6 characters")
          pintZip.Focus
          Return False
        ElseIf IsNumeric(pintZip) Then
          MsgBox("Congratulations, you have entered right Zip code")
          Return True
        End If
End Function

Try like this

UPDATE #1

Seems like you are using ASP.net not VB.net, here is the answer:

You can't show dialog box ON SERVER from ASP.NET application, it makes no sense since your user is using browser and it can't see message boxes on server. You have to understand how web sites work, server side code (ASP.NET in your case) produces html, javascript etc on server and then browser loads that content and displays it to the user, so in order to present modal message box to the user you have to use Javascript, for example alert function.

Here is the example for asp.net :

example

SOURCE

Community
  • 1
  • 1
Hoh
  • 1,196
  • 1
  • 12
  • 30
  • i tried bt i got error System.InvalidOperationException: Showing a modal dialog box or form when the application is not running in UserInteractive mode is not a valid operation. Specify the ServiceNotification or DefaultDesktopOnly style to display a notification from a service application. – anuj Mar 31 '14 at 11:08
  • 1
    Are you using ASP.net? Making browser application? – Hoh Mar 31 '14 at 11:33
  • srry bt i cannot find your answer,and the link whch you gave me doesnt exist – anuj Mar 31 '14 at 11:46