Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Hey Friends..plz help me out...

Hey Friends..plz help me out...

Scheduled Pinned Locked Moved ASP.NET
helpcsharplinqdesign
8 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10281574
    wrote on last edited by
    #1

    Hey friends...I am creating an online examination project...I have made the login...the admin part and even all the databse thing is done...but in the user side as i press the start exam button it givving "Object reference not set to an instance of an object. " error...please help me out ASAP...m about to meet the deadlines..and if i meet it i ll be dead... here's my code..

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public partial class Instruction : System.Web.UI.Page
    {

    OnlineExamsDataContext \_mycontext = new OnlineExamsDataContext();
    string username;
    
    protected void Page\_Load(object sender, EventArgs e)
    {
        **username = Request.QueryString\["username"\].ToString();**
        lbluname.Text = "Welcome   :" + username;
        lbldate.Text = System.DateTime.Now.ToString();
    
    
    }
    protected void btnstart\_Click(object sender, EventArgs e)
    {
        int emailid;
        emailid = \_mycontext.ExamTableInsert (Convert.ToDateTime (System.DateTime.Now.ToShortDateString()), Convert.ToInt32 (Request.QueryString\["UserID"\].ToString()), Convert.ToDecimal("0.0"));
        Response.Redirect("QuestionPaper.aspx");
    
    }
    protected void lbtnresult\_Click(object sender, EventArgs e)
    {
        Response.Redirect("Examresult.aspx");
    
    }
    

    }

    U B A Richard DeemingR B 6 Replies Last reply
    0
    • U User 10281574

      Hey friends...I am creating an online examination project...I have made the login...the admin part and even all the databse thing is done...but in the user side as i press the start exam button it givving "Object reference not set to an instance of an object. " error...please help me out ASAP...m about to meet the deadlines..and if i meet it i ll be dead... here's my code..

      using System;
      using System.Collections.Generic;
      using System.Linq;
      using System.Web;
      using System.Web.UI;
      using System.Web.UI.WebControls;

      public partial class Instruction : System.Web.UI.Page
      {

      OnlineExamsDataContext \_mycontext = new OnlineExamsDataContext();
      string username;
      
      protected void Page\_Load(object sender, EventArgs e)
      {
          **username = Request.QueryString\["username"\].ToString();**
          lbluname.Text = "Welcome   :" + username;
          lbldate.Text = System.DateTime.Now.ToString();
      
      
      }
      protected void btnstart\_Click(object sender, EventArgs e)
      {
          int emailid;
          emailid = \_mycontext.ExamTableInsert (Convert.ToDateTime (System.DateTime.Now.ToShortDateString()), Convert.ToInt32 (Request.QueryString\["UserID"\].ToString()), Convert.ToDecimal("0.0"));
          Response.Redirect("QuestionPaper.aspx");
      
      }
      protected void lbtnresult\_Click(object sender, EventArgs e)
      {
          Response.Redirect("Examresult.aspx");
      
      }
      

      }

      U Offline
      U Offline
      User 10281574
      wrote on last edited by
      #2

      it says Object reference not set to an instance of an object. is in the line which i have underlined....:'(

      1 Reply Last reply
      0
      • U User 10281574

        Hey friends...I am creating an online examination project...I have made the login...the admin part and even all the databse thing is done...but in the user side as i press the start exam button it givving "Object reference not set to an instance of an object. " error...please help me out ASAP...m about to meet the deadlines..and if i meet it i ll be dead... here's my code..

        using System;
        using System.Collections.Generic;
        using System.Linq;
        using System.Web;
        using System.Web.UI;
        using System.Web.UI.WebControls;

        public partial class Instruction : System.Web.UI.Page
        {

        OnlineExamsDataContext \_mycontext = new OnlineExamsDataContext();
        string username;
        
        protected void Page\_Load(object sender, EventArgs e)
        {
            **username = Request.QueryString\["username"\].ToString();**
            lbluname.Text = "Welcome   :" + username;
            lbldate.Text = System.DateTime.Now.ToString();
        
        
        }
        protected void btnstart\_Click(object sender, EventArgs e)
        {
            int emailid;
            emailid = \_mycontext.ExamTableInsert (Convert.ToDateTime (System.DateTime.Now.ToShortDateString()), Convert.ToInt32 (Request.QueryString\["UserID"\].ToString()), Convert.ToDecimal("0.0"));
            Response.Redirect("QuestionPaper.aspx");
        
        }
        protected void lbtnresult\_Click(object sender, EventArgs e)
        {
            Response.Redirect("Examresult.aspx");
        
        }
        

        }

        B Offline
        B Offline
        Blikkies
        wrote on last edited by
        #3

        Hey, Make sure your query string "username" exists. You are getting this error because you are trying to convert the a query string that is null to a string. best is to add an if statement:

        if (Request.QueryString["username"] != null) {
        username = Request.QueryString["username"].ToString();
        lbluname.Text = "Welcome :" + username;
        lbldate.Text = System.DateTime.Now.ToString();
        } else {

        //TODO
        }

        1 Reply Last reply
        0
        • U User 10281574

          Hey friends...I am creating an online examination project...I have made the login...the admin part and even all the databse thing is done...but in the user side as i press the start exam button it givving "Object reference not set to an instance of an object. " error...please help me out ASAP...m about to meet the deadlines..and if i meet it i ll be dead... here's my code..

          using System;
          using System.Collections.Generic;
          using System.Linq;
          using System.Web;
          using System.Web.UI;
          using System.Web.UI.WebControls;

          public partial class Instruction : System.Web.UI.Page
          {

          OnlineExamsDataContext \_mycontext = new OnlineExamsDataContext();
          string username;
          
          protected void Page\_Load(object sender, EventArgs e)
          {
              **username = Request.QueryString\["username"\].ToString();**
              lbluname.Text = "Welcome   :" + username;
              lbldate.Text = System.DateTime.Now.ToString();
          
          
          }
          protected void btnstart\_Click(object sender, EventArgs e)
          {
              int emailid;
              emailid = \_mycontext.ExamTableInsert (Convert.ToDateTime (System.DateTime.Now.ToShortDateString()), Convert.ToInt32 (Request.QueryString\["UserID"\].ToString()), Convert.ToDecimal("0.0"));
              Response.Redirect("QuestionPaper.aspx");
          
          }
          protected void lbtnresult\_Click(object sender, EventArgs e)
          {
              Response.Redirect("Examresult.aspx");
          
          }
          

          }

          A Offline
          A Offline
          ais07
          wrote on last edited by
          #4

          It is always best practice to convert object with Convert.ToString(Request.QueryString["username"]) instead of .ToString().Check whether you are getting username value as null.

          Life Is Beautiful

          Richard DeemingR 1 Reply Last reply
          0
          • A ais07

            It is always best practice to convert object with Convert.ToString(Request.QueryString["username"]) instead of .ToString().Check whether you are getting username value as null.

            Life Is Beautiful

            Richard DeemingR Offline
            Richard DeemingR Offline
            Richard Deeming
            wrote on last edited by
            #5

            Since Request.QueryString[key] already returns a string, there's absolutely no need to call either Convert.ToString or .ToString() to convert it to a string.


            "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

            "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

            1 Reply Last reply
            0
            • U User 10281574

              Hey friends...I am creating an online examination project...I have made the login...the admin part and even all the databse thing is done...but in the user side as i press the start exam button it givving "Object reference not set to an instance of an object. " error...please help me out ASAP...m about to meet the deadlines..and if i meet it i ll be dead... here's my code..

              using System;
              using System.Collections.Generic;
              using System.Linq;
              using System.Web;
              using System.Web.UI;
              using System.Web.UI.WebControls;

              public partial class Instruction : System.Web.UI.Page
              {

              OnlineExamsDataContext \_mycontext = new OnlineExamsDataContext();
              string username;
              
              protected void Page\_Load(object sender, EventArgs e)
              {
                  **username = Request.QueryString\["username"\].ToString();**
                  lbluname.Text = "Welcome   :" + username;
                  lbldate.Text = System.DateTime.Now.ToString();
              
              
              }
              protected void btnstart\_Click(object sender, EventArgs e)
              {
                  int emailid;
                  emailid = \_mycontext.ExamTableInsert (Convert.ToDateTime (System.DateTime.Now.ToShortDateString()), Convert.ToInt32 (Request.QueryString\["UserID"\].ToString()), Convert.ToDecimal("0.0"));
                  Response.Redirect("QuestionPaper.aspx");
              
              }
              protected void lbtnresult\_Click(object sender, EventArgs e)
              {
                  Response.Redirect("Examresult.aspx");
              
              }
              

              }

              Richard DeemingR Offline
              Richard DeemingR Offline
              Richard Deeming
              wrote on last edited by
              #6

              Just drop the .ToString() call - Request.QueryString["username"] already returns a string.

              username = Request.QueryString["username"];

              You also need to HTML-encode the value before you display it, to avoid cross-site scripting (XSS)[^]:

              lbluname.Text = "Welcome :" + HttpUtility.HtmlEncode(username)


              "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

              "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

              1 Reply Last reply
              0
              • U User 10281574

                Hey friends...I am creating an online examination project...I have made the login...the admin part and even all the databse thing is done...but in the user side as i press the start exam button it givving "Object reference not set to an instance of an object. " error...please help me out ASAP...m about to meet the deadlines..and if i meet it i ll be dead... here's my code..

                using System;
                using System.Collections.Generic;
                using System.Linq;
                using System.Web;
                using System.Web.UI;
                using System.Web.UI.WebControls;

                public partial class Instruction : System.Web.UI.Page
                {

                OnlineExamsDataContext \_mycontext = new OnlineExamsDataContext();
                string username;
                
                protected void Page\_Load(object sender, EventArgs e)
                {
                    **username = Request.QueryString\["username"\].ToString();**
                    lbluname.Text = "Welcome   :" + username;
                    lbldate.Text = System.DateTime.Now.ToString();
                
                
                }
                protected void btnstart\_Click(object sender, EventArgs e)
                {
                    int emailid;
                    emailid = \_mycontext.ExamTableInsert (Convert.ToDateTime (System.DateTime.Now.ToShortDateString()), Convert.ToInt32 (Request.QueryString\["UserID"\].ToString()), Convert.ToDecimal("0.0"));
                    Response.Redirect("QuestionPaper.aspx");
                
                }
                protected void lbtnresult\_Click(object sender, EventArgs e)
                {
                    Response.Redirect("Examresult.aspx");
                
                }
                

                }

                B Offline
                B Offline
                blachsmith
                wrote on last edited by
                #7

                Object reference not set to an instance of an object. it really means that when you request this page ,you haven't passed a param in the request. why not check the former page which entry this one?

                1 Reply Last reply
                0
                • U User 10281574

                  Hey friends...I am creating an online examination project...I have made the login...the admin part and even all the databse thing is done...but in the user side as i press the start exam button it givving "Object reference not set to an instance of an object. " error...please help me out ASAP...m about to meet the deadlines..and if i meet it i ll be dead... here's my code..

                  using System;
                  using System.Collections.Generic;
                  using System.Linq;
                  using System.Web;
                  using System.Web.UI;
                  using System.Web.UI.WebControls;

                  public partial class Instruction : System.Web.UI.Page
                  {

                  OnlineExamsDataContext \_mycontext = new OnlineExamsDataContext();
                  string username;
                  
                  protected void Page\_Load(object sender, EventArgs e)
                  {
                      **username = Request.QueryString\["username"\].ToString();**
                      lbluname.Text = "Welcome   :" + username;
                      lbldate.Text = System.DateTime.Now.ToString();
                  
                  
                  }
                  protected void btnstart\_Click(object sender, EventArgs e)
                  {
                      int emailid;
                      emailid = \_mycontext.ExamTableInsert (Convert.ToDateTime (System.DateTime.Now.ToShortDateString()), Convert.ToInt32 (Request.QueryString\["UserID"\].ToString()), Convert.ToDecimal("0.0"));
                      Response.Redirect("QuestionPaper.aspx");
                  
                  }
                  protected void lbtnresult\_Click(object sender, EventArgs e)
                  {
                      Response.Redirect("Examresult.aspx");
                  
                  }
                  

                  }

                  C Offline
                  C Offline
                  CIKolkataDeveloper
                  wrote on last edited by
                  #8

                  Is the value "username" correctly being passed in the querystring. The statement "Request.QueryString["username"].ToString();" is not getting the value from the querystring hence the error

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups