Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Referencing Controls on ItemTemplate in FormView Control

Reply
Thread Tools

Referencing Controls on ItemTemplate in FormView Control

 
 
mike@5starserv.com
Guest
Posts: n/a
 
      01-27-2007
in the Page_Load event the following code works at design time but
does not work when placed on the production server.

I get an error "Object reference not set to an instance of an object."

the snippet is:

Image img = new Image();
img = FormView1.Row.FindControl("ProdPhoto") as Image;
if (img.ImageUrl.Length < 20)
img.ImageUrl = "images/unavailable.jpg";

This is on a standard Webform without master page.

I've been scouring the net trying to find the resolution for this but
have not had any luck although I've tried several suggestions.

I've read in many places that the ItemTemplate should be the
default....this is the only template I am using currently in this
FormView control so I can't figure out why FindControl is not locating
the image.

 
Reply With Quote
 
 
 
 
David Thielen
Guest
Posts: n/a
 
      01-27-2007
I assume you are in a FromView. That control can only be found if the
ItemTemplate (view mode) is presently active. If you are in edit or create
mode those controls don't exist.

--
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"(E-Mail Removed)" wrote:

> in the Page_Load event the following code works at design time but
> does not work when placed on the production server.
>
> I get an error "Object reference not set to an instance of an object."
>
> the snippet is:
>
> Image img = new Image();
> img = FormView1.Row.FindControl("ProdPhoto") as Image;
> if (img.ImageUrl.Length < 20)
> img.ImageUrl = "images/unavailable.jpg";
>
> This is on a standard Webform without master page.
>
> I've been scouring the net trying to find the resolution for this but
> have not had any luck although I've tried several suggestions.
>
> I've read in many places that the ItemTemplate should be the
> default....this is the only template I am using currently in this
> FormView control so I can't figure out why FindControl is not locating
> the image.
>
>

 
Reply With Quote
 
 
 
 
mike@5starserv.com
Guest
Posts: n/a
 
      01-28-2007
David,

Thanks for the reply. I am only using the ItemTemplate in the
formview....I have it set for DefaultMode=ReadOnly. What gets me is
that it runs fine in design mode but not on the production server.

Mike

On Jan 27, 6:40 pm, David Thielen <(E-Mail Removed)> wrote:
> I assume you are in a FromView. That control can only be found if the
> ItemTemplate (view mode) is presently active. If you are in edit or create
> mode those controls don't exist.
>
> --
> thanks - dave
> david_at_windward_dot_nethttp://www.windwardreports.com
>
> Cubicle Wars -http://www.windwardreports.com/film.htm
>
>
>
> "(E-Mail Removed)" wrote:
> > in the Page_Load event the following code works at design time but
> > does not work when placed on the production server.

>
> > I get an error "Object reference not set to an instance of an object."

>
> > the snippet is:

>
> > Image img = new Image();
> > img = FormView1.Row.FindControl("ProdPhoto") as Image;
> > if (img.ImageUrl.Length < 20)
> > img.ImageUrl = "images/unavailable.jpg";

>
> > This is on a standard Webform without master page.

>
> > I've been scouring the net trying to find the resolution for this but
> > have not had any luck although I've tried several suggestions.

>
> > I've read in many places that the ItemTemplate should be the
> > default....this is the only template I am using currently in this
> > FormView control so I can't figure out why FindControl is not locating
> > the image.- Hide quoted text -- Show quoted text -


 
Reply With Quote
 
 
 
Reply

Thread Tools

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
strange inconsistency referencing controls in Formview itemtemplate Ned Balzer ASP .Net 4 08-03-2006 05:14 PM
Referencing child controls on a formview Neil ASP .Net 1 02-08-2006 09:32 AM
Referencing child controls on a formview Neil ASP .Net 0 02-07-2006 10:34 AM
can code inside a Repeater's ItemTemplate modify controls in the ItemTemplate? Bennett Haselton ASP .Net 1 09-24-2004 01:59 AM
Referencing a TextBox control in Javascript from DataList ItemTemplate Candice ASP .Net Datagrid Control 0 12-05-2003 07:11 AM



Advertisments