p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > ASP.NET and ASP > ASP.NET 2.0 > BOOK: Beginning ASP.NET 2.0 Databases Beta Preview
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 2.0 Databases Beta Preview
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 Databases: Beta Preview by John Kauffman, Thiru Thangarathinam; ISBN: 9780764570810

Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 Databases Beta Preview section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

 
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old June 16th, 2006, 01:25 PM
Registered User
 
Join Date: May 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks, Imar.

I got the code to work, but when I refreshed the page and ran the same code again, I got the following error message:

NullReferenceException was unhandled by user code
Object reference not set to an instance of an object.

Troubleshooting tips:
Use the "new" keyword to create an objct instance.
Check to determine if the objects is null before calling the method.
Get general help for this exception.


Thanks so much for your help...

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #12 (permalink)  
Old June 18th, 2006, 08:19 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Looks like the code can't find a control called Button1.

Is that defined in your page? What happens when you debug the app and set a break point at the line that retrieves the control? Do you get a valid reference?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
While typing this post, I was listening to: The Carnival Is Over by Nick Cave & the Bad Seeds (Track 14 from the album: Kicking Against the Pricks) What's This?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #13 (permalink)  
Old September 22nd, 2006, 05:55 PM
Authorized User
 
Join Date: Sep 2006
Location: Sunrise, FL, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am having a similar problem...

I have a web app that uses masterpages, a formview and a panel (within the formview). When I try to handle events for the controls within the formview (a button onclick event, for example), I am unable to access those controls. All controls that I am trying to reference are defined like this:

Dim ICarrier As DropDownList = fvCreateOrder.FindControl("ddlCarrier")

I tried dimming them using the same method that djpotte gives, but the result is the same.

All code I am using is in the code-behind for the page that the form is on (no stand-alone class files).

Anyone have any ideas?

Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #14 (permalink)  
Old September 23rd, 2006, 06:50 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Hi there,

Can you describe "I am unable to access those controls" in more detail? Do you get an exception, a null reference or are you controls not looking like the control you're expecting (e.g. not a true DropDownList, but a generic Control, for example?

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #15 (permalink)  
Old September 25th, 2006, 10:11 AM
Authorized User
 
Join Date: Sep 2006
Location: Sunrise, FL, USA.
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey Imar,

"unable to access..." means that, in my code-behind, the variable declaration I gave above is unable to "see" those controls. I get the "Object Reference Not Set to an Instance of Object" message.

To get around this, I have removed the FormView & will be creating the connection to the database manually & feeding in the form values programmatically.

I know there has to be a way to do this, but I am under a bit of a time-crunch, so I will have to go with the manual route (unless you have another idea)?

Thanks!

Phil
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #16 (permalink)  
Old September 25th, 2006, 12:49 PM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Hi Phil,

Not sure why that wouldn't work. I can successfully do something like this in some Click event:

Button myButton = (Button)FormView1.FindControl("Button1");

with the following FormView:

<asp:FormView ID="FormView1" runat="server">
  <ItemTemplate>
    <asp:Button ID="Button1" runat="server" Text="Button" />
    <asp:TextBox ID="TextBox1" runat="server" />
  </ItemTemplate>
</asp:FormView>

Maybe your controls are in another container inside the ItemTemplate? Also, you need to cast your controls to the proper type...

Cheers,

Imar
---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #17 (permalink)  
Old November 30th, 2006, 10:37 AM
Registered User
 
Join Date: Jun 2006
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I tried the solutions mentioned here but it's not working.

i have an image control in my formview which i need to programatically change, but i keep getting the "Object reference not set to an instance of an object" error. My code is below. can someone please help?

.ASPX FILE

<asp:Label ID="lblStudent_ID" runat="server" Text="Student ID" Font-Size="Small" Font-Names="Trebuchet MS"></asp:Label>  <asp:TextBox
            ID="txtStudent_ID" runat="server" Font-Size="Small" Font-Names="Trebuchet MS"></asp:TextBox>
        <asp:Button ID="btnSubmit" runat="server" Text="Submit" /><br /><br /></p>
<asp:FormView ID="FormViewMarksHeaders" runat="server" DataSourceID="MarksHeaders">
    <ItemTemplate>
    <p>
        <table width="100%" style="font-weight: bold">
            <tr>
                <td colspan="5"><asp:Image ID="imgCollege_Banner" runat="server" ImageUrl="~/Images/luzhou1.jpg" /><br /><br /></td>
            </tr>

.ASPX.VB FILE

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim imgChangeImage As Image
        imgChangeImage = CType(Me.FormViewMarksHeaders.FindControl("imgColl ege_Banner"), Image)
        imgChangeImage.ImageUrl = "~/Images/hubei.jpg"
End Sub


Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        Session("Roll") = txtStudent_ID.Text.ToUpper
        Response.Redirect("report2.aspx")
    End Sub

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #18 (permalink)  
Old December 2nd, 2006, 09:21 AM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Hi there,

Does the ODS MarksHeaders return any results?

If there's no data coming from that control, your ItemTemplate with the image won't show up in the FormView and you end up with a null reference for the image.

Hope this helps,

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #19 (permalink)  
Old December 14th, 2006, 12:47 PM
Registered User
 
Join Date: Dec 2006
Location: , , USA.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar, I am trying to do the same in a FormView_ModeChanged event and get a NullReferenceException to the DropDownList. It works just find in FormView_Load. Any ideas?
Thanks.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
  #20 (permalink)  
Old December 14th, 2006, 05:29 PM
Imar's Avatar
Wrox Author
Points: 33,554, Level: 80
Points: 33,554, Level: 80 Points: 33,554, Level: 80 Points: 33,554, Level: 80
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 10,228
Thanks: 7
Thanked 203 Times in 201 Posts
Default

Does your FormView already contain data when the event is fired? Maybe the event fires too soon, so there's no record and thus no drop down?

Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of ASP.NET 2.0 Instant Results and Beginning Dreamweaver MX / MX 2004
Want to be my colleague? Then check out this post.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Validation controls and FormView templates bpdsmark BOOK: Professional ASP.NET 2.0 and Special Edition; ISBN: 978-0-7645-7610-2; ISBN: 978-0-470-04178-9 1 September 28th, 2006 09:56 AM
CreateUserWizard -access controls inside templates vs .NET Framework 2.0 0 September 13th, 2006 10:01 PM
dynamic controls - referencing keyops VB.NET 0 February 14th, 2006 03:50 PM
Referencing Html Controls ~Bean~ ASP.NET 1.0 and 1.1 Basics 3 September 30th, 2005 10:11 AM
referencing controls in templates in form_view djpotte ASP.NET 2.0 Basics 3 May 25th, 2005 05:23 PM



All times are GMT -4. The time now is 12:52 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc