Hey Friends..plz help me out...
-
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"); }
}
-
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"); }
}
it says Object reference not set to an instance of an object. is in the line which i have underlined....:'(
-
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"); }
}
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
} -
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"); }
}
-
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
Since
Request.QueryString[key]
already returns astring
, there's absolutely no need to call eitherConvert.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
-
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"); }
}
Just drop the
.ToString()
call -Request.QueryString["username"]
already returns astring
.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
-
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"); }
}
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?
-
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"); }
}
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