Count number of charcters in a string – VB.NET

Code Behind

Dim count As Integer = 0
Dim CharCount As String = "Today is sunny day"

For Each c As Char In CharCount
   If Char.IsLetter(c) Or Char.IsNumber(c) Then
        count += 1
    End If
 Next
LblCharCount.Text = "Total number of characters is "& count.ToString()

Markup Page

<asp:Label ID="LblCharCount" runat="server" /></asp:Label>

ASP.NET Validator – validate one of the two values

Validate one of the two textbox values

Markup page

Please enter on of at least one contact point:
<asp:CustomValidator ID="ContactInfoAlert" runat="server" 
ErrorMessage="CustomValidator" OnServerValidate="CustomValidator_ServerValidate">
</asp:CustomValidator>

User email: 
<asp:TextBox ID="EmailTbx" runat="server" ToolTip="Enter email." >
</asp:TextBox>
User phone: 
<asp:TextBox ID="PhoneTbx" runat="server" ToolTip="Enter phone number." >
</asp:TextBox>
<asp:Button ID="Btn1" runat="server" Text="Next" CausesValidation="true"/>

Code-behind page

Protected Sub Btn1_Click(ByVal sender As Object, ByVal e As System.EventArgs) 
                         Handles Btn1.Click
Dim usrEmail As TextBox = Btn1.FindControl("EmailTbx")   'user email
Dim usrPhone As TextBox = Btn1.FindControl("PhoneTbx")   'user phone
'validate contact info - at least one required
  If usrEmailTbx.Text = "" AndAlso usrPhoneTbx.Text = "" Then
     ContactInfoAlert.ErrorMessage = "Enter email or phone!"
  Else
    'your code whatever it might be
  End If
End Sub
Public Sub CustomValidator_ServerValidate(ByVal source As Object, 
       ByVal args As System.Web.UI.WebControls.ServerValidateEventArgs)
        args.IsValid = True

  If memEmailTbx.Text = "" AndAlso memPhoneTbx.Text = "" Then
      ContactInfoAlert.ErrorMessage = "Enter email or phone!"

      args.IsValid = False
  End If
End Sub

Result

Enter email or phone!
User email:
User phone:

List Directory Content with Bulleted List Hyperlink – VB.NET

Code Behind

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
' make a reference to a directory
  Dim DirPath As New IO.DirectoryInfo("C:\\My_Website\My_Folder")
  Dim FCollect As IO.FileInfo() = DirPath.GetFiles()
  Dim FInfo As IO.FileInfo
        
'list the names of all files in the specified directory
    For Each FInfo In FCollect
     'bind url to line item - create hyperlink
      Dim LnItem = New ListItem(FInfo.ToString, "http://www.mywebsiteurl.com/" +
                                                 My_Folder/" & FInfo.ToString)
      'create bulleted list
      BulletedList1.Items.Add(LnItem)
      'open url in new window
      BulletedList1.Target = "_blank"
    Next
        
End Sub

Markup page

<form id="form1" runat="server">
  <div style="padding-left: 20px;">

   <asp:bulletedlist ID="BulletedList1" runat="server" DisplayMode="HyperLink" >
   </asp:bulletedlist>

   </div>
 </form>