473,396 Members | 1,775 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Help with Errors

I'm using the following two segments of code on ASPX pages with Datalists.

The following segment of code produces the error "Object reference not set
to an instance of an object."

Label lblPhone = (Label)(e.Item.FindControl("lblPhone"));
if (lblPhone.Text.Length > 0)
lblPhone.Text = string.Format("{0:(###)###-####}",
double.Parse(lblPhone.Text));

However, this segment of code works fine.

Label lblPhone = (Label)(e.Item.FindControl("lblClubPhone"));
if (lblPhone.Text.Length > 0)
lblPhone.Text = string.Format("{0:(###)###-####}",
double.Parse(lblPhone.Text));

Different pages same code same Datalist settings, same label properties.
I've even copied the label id's from the html into the code to make sure I
was not missing something there.

Does anyone have any ideas???
Nov 15 '05 #1
4 1040

Hi CDWaddell,

Thank you for posting in the community!

Based on my understanding, you use 2 code segments on different pages, but
one generates error, while the other works well.

===============================================
As you said, "Different pages same code same Datalist settings, same label
properties."
Actually, as I review, the 2 code segments is not the same. The 2
parameters for FindControl methods are not the same:
e.Item.FindControl("lblPhone")) e.Item.FindControl("lblClubPhone")

I think your Label control's id should be "lblClubPhone" not the
"lblPhone".
"Object reference not set to an instance of an object." error generates
because "Label lblPhone = (Label)(e.Item.FindControl("lblPhone"))" is a
null reference.

Normally, it is a good programming practice to check whether the reference
is null before using it.

===============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.
Have a nice day!!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #2
Jeffrey,

Actually I should have stated that the page objects are named lblPhone
on page A and lblClubPhone on page B. Other than the object ID's
everything is identical.

Thanks,
Cary

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 15 '05 #3

Hi Cary,

Thanks for your feedback.

Based on your feedback, you did not write the wrong parameter for the
FindControl method.

At this point, I think the information you provided is not enough for find
out the problem. Can you provide the more detailed code and other
information?

Which code does this exception generate? If it generate in the code you
pasted, I think the FindControl method just returns a null reference. (You
can determine this using code)

I will wait for your further feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #4

Hi Cary,

Does my reply make sense to you?
If you have the further information, please feel free to post, I will help
you.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Nov 15 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: MSM | last post by:
Hello, This may be posted twice if so i apologize. I am creating a form using php where the information entered into the form will go into a database. When creating the tables in SQL where do I...
8
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- ...
6
by: Jax | last post by:
I have Visual Studio 2002 Standard Edition. It has been working fine up to a point and now i'm at that point. Due to the limitations of the edition i am not using any of my own .dll's and instead...
0
by: clemrock | last post by:
Help w/ errors.add_to_base between controller and model Hello, I'm having trouble in routing some errors between model and controller. The errors produced in the controller...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
3
by: Learner | last post by:
Hello, I recently converted a VS 2003 application to VS 2005. When I compile it in VS 2005 every thing gets compiled with no errors. But when I try publishing the website I get all different...
4
by: Damodhar | last post by:
Any one help me to parse the bellow xml feed please .. =========================================================== <item> <title>Green earthquake alert Japan(M=6.8) potentially affecting 4.6...
11
by: tracy | last post by:
Hi, I really need help. I run this script and error message appeal as below: drop trigger log_errors_trig; drop trigger log_errors_trig ERROR at line 1: ORA04080: trigger 'LOG_ERRORS-TRIG'...
9
by: beet | last post by:
Hi, I am really not good at c/c++. Some simple code.. #include <stdio.h> #include <stdlib.h> #include <math.h> #include "simlibdefs.h"
11
by: A.C. | last post by:
hi i m declaring a structure globally & there is func1 & main. i m assigning the value to variable(this is a pointer) of structure in fun1 & want to print it in main. this is same kind of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.