Object reference not set to an instance of an object.

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)
   System.Web.UI.Page.ProcessRequestMain()






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

6784

6784Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DabasCommented:
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
        ...

Dabas
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
6784Author Commented:
Dabas,

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.

6784
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.