0

I'm trying to make a check for a text box written in HTML, but it keeps throwing exceptions :

public partial class First : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string username = "";
        username = Request.QueryString["UsernameBox"];
        int i;
        for (i = 0; i < 10; i++)
        {
            if (username[i] < 'a' && username[i] > 'z' && username[i] < 'A' && username[i] > 'Z')
            {
                Response.Write("NO");
                break;
            }
            else
                Response.Redirect("Second.aspx");
        }
    }
}

The errors :

Object reference not set to an instance of an object.

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 15: for (i = 0; i < 10; i++)

Line 16: {

Line 17: if (username[i] < 'a' && username[i] > 'z' && username[i] < 'A' && username[i] > 'Z')

Line 18: {

Line 19: Response.Write("NO");

Source File: c:\Users\User\Desktop\SE Assignment\First.aspx.cs Line: 17

Community
  • 1
  • 1

0 Answers0