Solved

Object reference not set to an instance of an object

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
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…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
This is a video that shows how the OnPage alerts system integrates into ConnectWise, how a trigger is set, how a page is sent via the trigger, and how the SENT, DELIVERED, READ & REPLIED receipts get entered into the internal tab of the ConnectWise …

919 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

17 Experts available now in Live!

Get 1:1 Help Now