Usercontrols asp.net textbox/validator controls
I want to combine a textbox and several validator controls into 1 usercontrol. Is this possible with the intent to keep some fields dynamic like
textbox:cssclass textbox:id textbox:width
I'm asking this because i find myself putting a lot of validator controls for every (same textbox type) field in my f开发者_C百科orm and it's getting kinda messy.
Kind regards, Mark
Build your usercontrol with properties that pass through to the textboxes. So for example, you'd include your ascx like:
<cc1:MyUserControl runat="server" TextBoxWidth="50"
TextBoxId="txtID" TextBoxCssClass="class" />
In the code for your user control, simply create these properties:
public int TextBoxWidth { get; set; }
public string TextBoxID { get; set; }
public string TextBoxCssClass { get; set;}
And in the code somewhere, pass the properties through to your textbox control. PreRender would be a good place to do it.
...
myTxtControl.Width = this.TextBoxWidth;
myTextControl.ID = this.TextBoxID;
myTextControl.CssClass = this.TextBoxCssClass;
...
where myTextControl is the textbox that your usercontrol contains.
精彩评论