You must Sign In to post a response.
  • Category: ASP.NET

    Why not getting Request.QueryString value in asp.net

    Hi,
    I am passing value to another form from dropdowlist and textbox.
    But I not getting Request.QueryString value in another aspx page.
    So it is showing error..
    'Object reference not set to an instance of an object.'

    First form code:
    ----------------
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    GM.SetProjectData(this.ddlProjectName, 0);

    this.ddlProjectName.Items.Insert(1, new ListItem("All", "-1"));

    this.GetProjectTollData();

    this.tbStartDate.Attributes.Add("readOnly", "readOnly");

    string _URL = "javascript:window.open('NewDefaultTollResult.aspx?ProjectName=" + this.ddlProjectName.SelectedIndex + "TollID=0" + "TollDate=" + this.tbStartDate.Text.ToString() + "');";

    bFind.Attributes.Add("onclick", _URL);
    }
    }


    protected void bFind_Click(object sender, EventArgs e)
    {
    TollEntity tollEntity;
    TollLogic tollLogic;

    try
    {
    tollEntity = new TollEntity();
    tollLogic = new TollLogic();

    if (GM.ConvertToDate(this.tbStartDate.Text) == GM.ConvertToDate(DateTime.Now.ToString("dd-MM-yyyy")))
    {
    ScriptManager.RegisterStartupScript(this, this.GetType(), "Msg", "alert('Invalid Date, You cannot check today Date..');", true);
    return;
    }

    if (this.ddlProjectName.SelectedIndex > 0 && this.ddlTollName.Items.Count == 0 && this.tbStartDate.Text.Trim() != string.Empty)
    {

    ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('NewDefaultTollResult.aspx?ProjectName=" + this.ddlProjectName.SelectedValue + "TollID= 0" + "TollDate=" + this.tbStartDate.Text.ToString() + "');", true);
    }
    else if (this.ddlProjectName.SelectedIndex > 0 && this.ddlTollName.SelectedIndex > 0 && this.tbStartDate.Text.Trim() != string.Empty)
    {

    ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('NewDefaultTollResult.aspx?ProjectName=" + this.ddlProjectName.SelectedIndex + "TollID=" + this.ddlTollName.SelectedValue + "TollDate=" + this.tbStartDate.Text.ToString() + "');", true);
    }

    //this.GetProjectTollData();
    }
    catch (Exception ex)
    {
    throw ex;
    }
    finally
    {
    tollEntity = null;
    tollLogic = null;
    source = null;
    }
    }


    Second form code:
    ----------------
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!IsPostBack)
    {
    if (Request.QueryString["ProjectName"].ToString() != string.Empty && Request.QueryString["TollID"].ToString() != string.Empty && Request.QueryString["TollDate"].ToString() != string.Empty)
    {
    this.SetProjectTollData();
    }
    }
    }
  • #769077
    Hi,

    This error is caused because you are trying to access a property of an object that is null.

    Whenever you get this sort of error, you can try to step through and debug your source code.
    This will help you get to the line that is throwing the error.

    You can take a look at which object is null and then fix this error by figuring out why this object is null in your code.

    To understand is that really null, Check like following


    string _URL = "javascript:window.open('NewDefaultTollResult.aspx?ProjectName=" + TestProj + "TollID=0" + "TollDate=" + this.tbStartDate.Text.ToString() + "');";


    hardcode some value in the Project Name parameter and check it out you are getting the projname in the next function.

    Thanks,
    Mani

  • #769093
    Hi,

    As per error 'Object reference not set to an instance of an object.' whenever you try to assign null value to some object that time you may get this type of error.

    My suggestion to assign any value before that you have to check whether it is null or not null. if not null then assign value otherwise skip for assign.

    Ex:

    if(value!=null)
    {
    int i=value;
    }


    Hope this helps you...

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #769102
    ''Object reference ' error indicates you are trying to access NULL value, when your query string is NULL at that time application is throwing the exception.
    before accessing value from 'Request.QueryString' check if it is NULL

    if(Request.QueryString["val1"] != null)
    {
    //your code goes here
    }
    else
    {
    //query string is NULL
    }

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #769123
    You can try this code example in C# to getting Request.QueryString value in asp.net
     string fullname1 = Request.QueryString["fullname"];
    string fullname2 = Request["fullname"];/code]


  • Sign In to post your comments