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. A simple composite control

A simple composite control

Scheduled Pinned Locked Moved ASP.NET
helphtmlquestion
3 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.
  • M Offline
    M Offline
    markymark82
    wrote on last edited by
    #1

    Hi All, I'm tring to create a very simple composite control, consisting of a textbox and a label (and some html to style it..) I have created it and at first it seemed to work, but now it appears I have missed out something fundamental. I have a Text property in which I am setting the text property of the child text control and retreiving the same child property.

    public string Text
    {
    get
    {
    EnsureChildControls();
    return childTextBox.Text;
    }
    set
    {
    EnsureChildControls();
    childTextBox.Text = value;
    }
    }

    This works fine, unless on loading the page containing the control, I assign some text to the Text property. The text I assign appears in the child textbox fine, but when edited and attemped to save, it loses the new child textbox value, and reverts to the Text property as it was set on page load (or any other event that I use to populate it). I'm guessing it's some kind of viewstate issue? Though this is the first time I have attempted a custom control of any sort and the help I've been looking up has led to me breaking it completely a number of time while trying various solutions. If anyone has any idea what the problem is, then I'd appreciate your help as I'm running out of time to spend on it and don't want to have to abandon it because of deadlines. Thanks in advance.. Mark

    D 1 Reply Last reply
    0
    • M markymark82

      Hi All, I'm tring to create a very simple composite control, consisting of a textbox and a label (and some html to style it..) I have created it and at first it seemed to work, but now it appears I have missed out something fundamental. I have a Text property in which I am setting the text property of the child text control and retreiving the same child property.

      public string Text
      {
      get
      {
      EnsureChildControls();
      return childTextBox.Text;
      }
      set
      {
      EnsureChildControls();
      childTextBox.Text = value;
      }
      }

      This works fine, unless on loading the page containing the control, I assign some text to the Text property. The text I assign appears in the child textbox fine, but when edited and attemped to save, it loses the new child textbox value, and reverts to the Text property as it was set on page load (or any other event that I use to populate it). I'm guessing it's some kind of viewstate issue? Though this is the first time I have attempted a custom control of any sort and the help I've been looking up has led to me breaking it completely a number of time while trying various solutions. If anyone has any idea what the problem is, then I'd appreciate your help as I'm running out of time to spend on it and don't want to have to abandon it because of deadlines. Thanks in advance.. Mark

      D Offline
      D Offline
      dan sh
      wrote on last edited by
      #2

      Where are you setting the default value for the textbox? In the Load event of your user control? Have you place that inside if(!IsPostBack) block?

      50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

      M 1 Reply Last reply
      0
      • D dan sh

        Where are you setting the default value for the textbox? In the Load event of your user control? Have you place that inside if(!IsPostBack) block?

        50-50-90 rule: Anytime I have a 50-50 chance of getting something right, there's a 90% probability I'll get it wrong...!!

        M Offline
        M Offline
        markymark82
        wrote on last edited by
        #3

        Hi, Thanks for the reply. Yes it was in the page load and even though I tried it on other events, I somehow never remembered to remove the onload version of the event, coupled with it not being in a (!Page.IsPostBack) block. Having done that, it works just fine. Thanks for pointing out the error, I'd spent so long looking for problems with the control, I didn't even think it could be with my page :doh: Thanks again Mark

        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