Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Settings a webusercontrol object's property

Settings a webusercontrol object's property

Scheduled Pinned Locked Moved ASP.NET
helpquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    TheFM234
    wrote on last edited by
    #1

    I'm trying to add a webusercontrol I've created dynamically through a page. I have the properties all set up correctly, and those are working. What happens when the Page_Load is that the labels that I have in the control are still null when the Page_Load runs, so a NullReferenceNotHandled exception is thrown when I try to access a label's Text property. What am I doing wrong? Maybe I'm using the webusercontrol in the wrong way, I'm used to writing desktop applications... He's the code I'm using, assume that I have the correct code for the properties

    public NewsPost(string title, string date, string message, int newsId)
    {
        this.Title = title;
        this.Date = date;
        this.Message = message;
        this.NewsId = newsId;
    }
    
    protected void Page\_Load(object sender, EventArgs e)
    {
        lblTitle.Text = Title; //NullReferenceNotHandled error is thrown here
        lblDate.Text = Date;
        lblMessage.Text = Message;
    }
    
    C 1 Reply Last reply
    0
    • T TheFM234

      I'm trying to add a webusercontrol I've created dynamically through a page. I have the properties all set up correctly, and those are working. What happens when the Page_Load is that the labels that I have in the control are still null when the Page_Load runs, so a NullReferenceNotHandled exception is thrown when I try to access a label's Text property. What am I doing wrong? Maybe I'm using the webusercontrol in the wrong way, I'm used to writing desktop applications... He's the code I'm using, assume that I have the correct code for the properties

      public NewsPost(string title, string date, string message, int newsId)
      {
          this.Title = title;
          this.Date = date;
          this.Message = message;
          this.NewsId = newsId;
      }
      
      protected void Page\_Load(object sender, EventArgs e)
      {
          lblTitle.Text = Title; //NullReferenceNotHandled error is thrown here
          lblDate.Text = Date;
          lblMessage.Text = Message;
      }
      
      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      Dynamically adding controls is always grief. A better way to do it is to build a collection of news item object and then bind them to a data driven control, in order to shoe them.

      Christian Graus Driven to the arms of OSX by Vista.

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups