Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 6th, 2007, 08:27 AM
pbb pbb is offline
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default using FindControl after ChangeMode in a FormView

Hi all,

I think my problem lies in not being able to find controls after performing a ChangeMode on a FormView.

Much simplified code:

Code:
if (true)
{
  FormView1.ChangeMode(FormViewMode.Edit);
  Trace.Write (((TextBox)FormView1.FindControl("SomeEditControl")).Text);
}
This results in "Object reference not set to an instance of an object".

The idea is to have a FormView which is set to Edit mode when a certain datafield is NULL, and give the databound TextBox a default value retrieved from a Cookie.

How should I access the TextBox control?

Hope you can help,
Peter
 
Old March 6th, 2007, 10:11 AM
pbb pbb is offline
Registered User
 
Join Date: Sep 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, we found the solution. The code was inside the FormView1_DataBound procedure, which apparently gets executed twice, and only on second try the FindControl function returns anything. So I've added a check to see if FindControl returns anything, and now everything works :-)





Similar Threads
Thread Thread Starter Forum Replies Last Post
FormView ChangeMode Question mikener ASP.NET 2.0 Professional 0 August 12th, 2008 09:30 AM
FindControl in DataListItem SKhna ASP.NET 2.0 Basics 1 February 29th, 2008 05:15 PM
FindControl Wervis C# 7 November 30th, 2005 09:51 AM
FindControl dkr72 Excel VBA 0 January 19th, 2005 09:55 AM
Problem with FindControl RussC Excel VBA 1 June 16th, 2004 11:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.