Answered by:
TypeConverter in Web user control

Question
-
User1168546875 posted
I am developing a web user control and have a property exposed of type object. What I want is that when this user control is placed on a web form this property will pick up all the textboxes and give the user an option to choose from those values. Something very similar to what we've in CompareValidator where we get to choose the name of the control to compare etc.Just to be more clear:
a.) On a web form I'll place my user control.
b.) User control has a property, TextBoxToFill.
c.) Developer will go into the property and then he should see a list of all the textboxes that are available on the current web form (where the user control has been placed).
What I've tried so far:
In a CustomCompareValidator I've put the attributeTypeConverter(GetType(ControlIDConverter))Tuesday, April 1, 2008 4:44 PM
Answers
-
User-1136466523 posted
Hi,
Yes. It should be applied to Custom Server controls instead of the user control.
Thanks.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 7, 2008 10:31 PM
All replies
-
User-1136466523 posted
Hi,
You can achieve that through ValidatedControlConverter. Try the following code snippet:
[TypeConverter(typeof(ValidatedControlConverter))]
public string TextBoxToFill
{get
{
object obj2 = this.ViewState["TextBoxToFill"];
if (obj2 != null)
{
return (string)obj2;
}
return string.Empty;
}
set
{
this.ViewState["TextBoxToFill"] = value;
}
}Thanks.
Sunday, April 6, 2008 10:57 PM -
User1168546875 posted
Thanks Jin for your response but that didn't work out. I am coding in VB.Net and below is what I implemented:
<TypeConverter(GetType(ValidatedControlConverter))> _ Public Property TextboxToFill() As String Get Dim obj As New Object obj = Me.ViewState("TextboxToFill") If Not obj Is Nothing Then Return obj.ToString End If Return String.Empty End Get Set(ByVal value As String) Me.ViewState("TextboxToFill") = value End Set End Property
One thing that I notice is that all Type converters belong to System.Web.UI.Webcontrols while my user control inherits from System.Web.UI.UserControl. Is that the reason this is not working out?
Thanks.
Monday, April 7, 2008 11:07 AM -
User-1136466523 posted
Hi,
Yes. It should be applied to Custom Server controls instead of the user control.
Thanks.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Monday, April 7, 2008 10:31 PM