Solved

Object reference not set to an instance of an object

Posted on 2006-07-07
3
595 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
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…

685 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