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