Solved

Object reference not set to an instance of an object

Posted on 2006-07-07
3
590 Views
Last Modified: 2007-12-19
Hello Experts,

I am getting the error below;-

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 38:
Line 39:
Line 40:         string fullarticle = myArticle.Text.Replace("<", "<");
Line 41:         string status = "live";
Line 42:         UpdateNews.UpdateNewsArticle(ARTICLEID, title, shortdesc, fullarticle, status);
 
This is what am doing;-
using FreeTextBoxControls;

protected void Button1_Click(object sender, EventArgs e)
{
     FreeTextBox myArticle = (FreeTextBox)this.FindControl("FreeTextBox1");
    string fullarticle = myArticle.Text.Replace("<", "<");  <-------------------------------------LINE WITH ERROR----------------->

}

What am I missing?

       
0
Comment
Question by:claracruz
3 Comments
 
LVL 7

Expert Comment

by:kGenius
ID: 17056994
I think the object myArticle was not found by the this.FindControl function.

you must specify "this" more narrow(?)
ie if FreeTextBox1 is added on a panel you should do Panel1.FindControl("FreeTextBox1")

Or you can loop through all the controls and childcontrols of these controls until you find FreeTextBox1.

Try to step through your code and see if this.FindControl("FreeTextBox1") returns any FreeTextBox

kGenius
0
 
LVL 3

Accepted Solution

by:
harshits earned 500 total points
ID: 17057008
Hi,

The problem is that in this line

FreeTextBox myArticle = (FreeTextBox)this.FindControl("FreeTextBox1");

your myArticle object is not initialized with the reference from this.FindControl("FreeTextBox1"). Meaning this.FindControl("FreeTextBox1") is not able to find and return a reference of FreeTextBox1 object back to your myArticle object, hence the error.

Is "FreeTextBox" a third party control?, because it probably looks like that is causing the error.

Harshit Sheth
0
 
LVL 4

Author Comment

by:claracruz
ID: 17057070
Hello,
Got it, swapped;-

this.FindControl("FreeTextBox1")

FormView1.FindControl("FreeTextBox1")
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

707 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

16 Experts available now in Live!

Get 1:1 Help Now