Solved

Object reference not set to an instance of an object

Posted on 2006-07-07
3
598 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

In an ASP.NET application, I faced some technical problems. In this article, I list them out and show the solutions that I found.  I hope it will be useful. Problem: After closing a pop-up window, the parent page should be refreshed automaticall…
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 …
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

630 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