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. Custom Control property problem

Custom Control property problem

Scheduled Pinned Locked Moved ASP.NET
helpquestion
5 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.
  • D Offline
    D Offline
    Dirso
    wrote on last edited by
    #1

    Hi, I created a webcontrol (Textbox derivated) and I have a property that was suppose to link a Label control to it - when my control gets the focus, I'm gonna change some style from the assigned label. Here is my code... When I select the Label, my text box disappears and show an error "Error Rendering Control ... Cannot create an object from its string representation"... How can I fix it?

        public virtual Label Label
        {
            get
            {
                object label = ViewState\["Label"\];
                if (label == null)
                    return null;
                return (Label)Page.FindControl((string)label);
            }
            set
            {
                ViewState\["Label"\] = value.UniqueID;
            }
        }
    

    Thanks, Dirso

    D C 2 Replies Last reply
    0
    • D Dirso

      Hi, I created a webcontrol (Textbox derivated) and I have a property that was suppose to link a Label control to it - when my control gets the focus, I'm gonna change some style from the assigned label. Here is my code... When I select the Label, my text box disappears and show an error "Error Rendering Control ... Cannot create an object from its string representation"... How can I fix it?

          public virtual Label Label
          {
              get
              {
                  object label = ViewState\["Label"\];
                  if (label == null)
                      return null;
                  return (Label)Page.FindControl((string)label);
              }
              set
              {
                  ViewState\["Label"\] = value.UniqueID;
              }
          }
      

      Thanks, Dirso

      D Offline
      D Offline
      Dirso
      wrote on last edited by
      #2

      It would be nice when someone marks my question as a "Bad Question" tell me why. It might be the solution to my problem and I would vote for him as a big 5. Thanks, Dirso

      1 Reply Last reply
      0
      • D Dirso

        Hi, I created a webcontrol (Textbox derivated) and I have a property that was suppose to link a Label control to it - when my control gets the focus, I'm gonna change some style from the assigned label. Here is my code... When I select the Label, my text box disappears and show an error "Error Rendering Control ... Cannot create an object from its string representation"... How can I fix it?

            public virtual Label Label
            {
                get
                {
                    object label = ViewState\["Label"\];
                    if (label == null)
                        return null;
                    return (Label)Page.FindControl((string)label);
                }
                set
                {
                    ViewState\["Label"\] = value.UniqueID;
                }
            }
        

        Thanks, Dirso

        C Offline
        C Offline
        Christian Graus
        wrote on last edited by
        #3

        Why are you storing the label in ViewState ? Why not just create a label and refer to it by name ? Your core issue imo is that your code requires postback. If you want to change a page when a control gets focus, you definately want to do it on the client, in javascript.

        Christian Graus Driven to the arms of OSX by Vista.

        D 1 Reply Last reply
        0
        • C Christian Graus

          Why are you storing the label in ViewState ? Why not just create a label and refer to it by name ? Your core issue imo is that your code requires postback. If you want to change a page when a control gets focus, you definately want to do it on the client, in javascript.

          Christian Graus Driven to the arms of OSX by Vista.

          D Offline
          D Offline
          Dirso
          wrote on last edited by
          #4

          I'm kinda n00bie on server controls development (big surprise hum :)) I created a script (using javascript) that would do the trick of changing colors and styles. I use this, because I'm creating several forms and in each form there are several textboxes (my textboxes) and so, everytime a textbox gets the focus, the assigned label should have it's style changed too. Back to the problem, at design time, i want to select in the property window (of each textbox) the label it should change the style from. I read about TypeConverters, but still not sure how to use it... I'm learning about it now.. Thanks, Dirso

          C 1 Reply Last reply
          0
          • D Dirso

            I'm kinda n00bie on server controls development (big surprise hum :)) I created a script (using javascript) that would do the trick of changing colors and styles. I use this, because I'm creating several forms and in each form there are several textboxes (my textboxes) and so, everytime a textbox gets the focus, the assigned label should have it's style changed too. Back to the problem, at design time, i want to select in the property window (of each textbox) the label it should change the style from. I read about TypeConverters, but still not sure how to use it... I'm learning about it now.. Thanks, Dirso

            C Offline
            C Offline
            Christian Graus
            wrote on last edited by
            #5

            I'm not sure about type converters. you'd need to use the ClientID property of the label to get the client side label for your JS to use, I'd just have a property which takes the label in question and gets it's id, and then investigate making this available in the designer.

            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