Object reference not set to an instance of an object.

Posted on 2004-11-05
Last Modified: 2010-04-23
Can yoy guys look at this very basic code and tell my I get this error.

Line 1583:            'End If
Line 1584:
Line 1585:            If ddlCashAccount.SelectedItem.Text = "" Then
Line 1586:
Line 1587:                strScript = "<script>"

[NullReferenceException: Object reference not set to an instance of an object.]
   iVMF.wfmMain.MissingRequiredFields() in c:\inetpub\wwwroot\VB\iVMF\wfmMain.aspx.vb:1585
   iVMF.wfmMain.btnVMSave_Click(Object sender, EventArgs e) in c:\inetpub\wwwroot\VB\iVMF\wfmMain.aspx.vb:1895
   System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)

If ddlCashAccount.SelectedItem.Text = "" Then

                strScript = "<script>"

                strScript = strScript & "alert('Invaild Cash Account! Cash Account is mandatory on Vendor Company tab.');"

                strScript = strScript & "</script>"

                Page.RegisterStartupScript("ClientScript", strScript.ToString())

                Exit Function
            End If

I seem to be getting alot of these errors


Question by:6784
    LVL 27

    Accepted Solution

    Hi 6784:

    Probably ddlCashAccount has no selected item yet. Hence ddlCashAccount.SelectedItem is nothing, hence hte exception.

    Try the following instead:

    If not ddlCashAccount.SelectedItem is Nothing then


    Author Comment


    Yes, that could very well be the problem. I'm stepping through the vaildation code, without entering any data or selecting any items in the ddls.

    Thanks for the quick response.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now