Hi all,
I need to extend RadSearchBox because this concept with only Text value (that is not persisted) now is unusable.
Lets say I have a case when I need to set a City to a Person. I have foreign key of the City in the Person entity and I am editing it. Lets also say there are 5 cities of the same name so I need to set VALUE (eg. foreign key) and text is pretty much unusable at this point. I cannot have preset city (if I am editing existing Person that moved to another city) and also I can only get the value after the user selected it (in event) so I cannot have 2 way binding here because VALUE field is only available in Search event.
So my question here is how do I extend RadSearchBox to have VALUE field in 2 way binding scenario? I tried to extend RadSearchBox with 2 hidden fields and overried OnSearch event to store Text and Value in those fields but OnSearch is not overridable so I need some other way to make Value and Text fields persistent or use some other control (please advise which).
Here is my code that I tried which obviously does not work:
I need to extend RadSearchBox because this concept with only Text value (that is not persisted) now is unusable.
Lets say I have a case when I need to set a City to a Person. I have foreign key of the City in the Person entity and I am editing it. Lets also say there are 5 cities of the same name so I need to set VALUE (eg. foreign key) and text is pretty much unusable at this point. I cannot have preset city (if I am editing existing Person that moved to another city) and also I can only get the value after the user selected it (in event) so I cannot have 2 way binding here because VALUE field is only available in Search event.
So my question here is how do I extend RadSearchBox to have VALUE field in 2 way binding scenario? I tried to extend RadSearchBox with 2 hidden fields and overried OnSearch event to store Text and Value in those fields but OnSearch is not overridable so I need some other way to make Value and Text fields persistent or use some other control (please advise which).
Here is my code that I tried which obviously does not work:
public
class
RadSearchBoxExtender : RadSearchBox, INamingContainer
{
#region Public properties.
public
string
Value
{
get
{
this
.EnsureChildControls();
return
this
.valueField.Value;
}
set
{
this
.EnsureChildControls();
this
.valueField.Value = value;
}
}
public
override
string
Text
{
get
{
this
.EnsureChildControls();
return
this
.textField.Value;
}
set
{
this
.EnsureChildControls();
this
.textField.Value = value;
base
.Text = value;
}
}
#endregion Public properties.
#region Private methods.
private
HiddenField valueField;
private
HiddenField textField;
private
string
valueFieldId
{
get
{
return
this
.ID +
"_Value"
;
}
}
private
string
textFieldId
{
get
{
return
this
.ID +
"_Text"
;
}
}
#endregion Private methods.
#region Overrides.
protected
override
void
CreateChildControls()
{
this
.valueField =
new
HiddenField();
this
.valueField.ID =
this
.valueFieldId;
this
.valueField.Value =
null
;
this
.textField =
new
HiddenField();
this
.textField.ID =
this
.valueFieldId;
this
.textField.Value =
null
;
this
.Controls.Add(
this
.valueField);
this
.Controls.Add(
this
.textField);
base
.CreateChildControls();
}
#endregion Overrides.
protected
new
void
OnSearch(SearchBoxEventArgs e)
{
base
.OnSearch(e);
this
.EnsureChildControls();
this
.valueField.Value = e.Value;
this
.textField.Value = e.Text;
}
protected
override
void
OnInit(EventArgs e)
{
base
.OnInit(e);
}
protected
override
void
OnPreRender(EventArgs e)
{
base
.OnPreRender(e);
}
protected
override
void
Render(System.Web.UI.HtmlTextWriter writer)
{
base
.Render(writer);
this
.valueField.RenderControl(writer);
}
}