Referencing Controls on ItemTemplate in FormView Control

Discussion in 'ASP .Net Web Controls' started by mike@5starserv.com, Jan 27, 2007.

  1. Guest

    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.
     
    , Jan 27, 2007
    #1
    1. Advertising

  2. 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




    "" 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.
    >
    >
     
    David Thielen, Jan 27, 2007
    #2
    1. Advertising

  3. Guest

    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 <> 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
    >
    >
    >
    > "" 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 -
     
    , Jan 28, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bennett Haselton
    Replies:
    1
    Views:
    5,341
    Joe Fallon
    Sep 24, 2004
  2. Neil
    Replies:
    0
    Views:
    564
  3. Neil
    Replies:
    1
    Views:
    483
  4. Ned Balzer
    Replies:
    4
    Views:
    2,449
    Ned Balzer
    Aug 3, 2006
  5. Candice
    Replies:
    0
    Views:
    246
    Candice
    Dec 5, 2003
Loading...

Share This Page