Solved

Object reference not set to an instance of an object

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

808 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