I'm creating a Custom Field that shows me multiple links... In edit or new mode it uses an Asset Picker to let the user choose links... When the item is display in the view it shows (using overriding of GetFieldValueAsHtml and getType) and seems to work great..
The problem i'm facing appears when i Diplay the single Item (clicking on it). It shows me the "default value" and not the controls created by the create child control i write down... Debugging i can see he goes in the code part, but this does not affect my html response.. Any suggestion?? Is there anything else to override?
protected override void CreateChildControls()
{
base.CreateChildControls();
if ((base.ControlMode == SPControlMode.New) || (base.ControlMode == SPControlMode.Edit))
{
list = new DVListBox();
list.Width = 380;
this.Controls.Add(list);
HtmlGenericControl br = new HtmlGenericControl("br");
this.Controls.Add(br);
urlSelector = new AssetUrlSelector();
urlSelector.PickerButtonText = "Add";
//urlSelector.AssetUrlTextBoxVisible = false;
urlSelector.AutoPostBack = true;
this.Controls.Add(urlSelector);
HtmlGenericControl br2 = new HtmlGenericControl("br");
this.Controls.Add(br2);
HtmlInputButton remove = new HtmlInputButton();
remove.ID = "REMOVE_ITEM";
remove.Value = "Remove";
remove.Style.Add(HtmlTextWriterStyle.Width, "150px");
remove.ServerClick += new EventHandler(reset_ServerClick);
this.Controls.Add(remove);
HtmlInputButton reset = new HtmlInputButton();
reset.ID = "RESET_FIELD";
reset.Value = "Reset Field";
reset.Style.Add(HtmlTextWriterStyle.Width, "150px");
reset.ServerClick += new EventHandler(reset_ServerClick);
this.Controls.Add(reset);
if (ViewState["Links"] == null)
{
if (this.ItemFieldValue == null)
{
ViewState["Links"] = new List<string>();
}
else
{
ViewState["Links"] = ConvertStringToList((string)this.ItemFieldValue);
list.DataSource = ViewState["Links"];
list.DataBind();
}
}
}
else
{
if (base.ControlMode == SPControlMode.Display)
{
StringBuilder sb = new StringBuilder();
using (SPWeb spWeb = SPContext.Current.Web)
{
string[] indirizzi = base.ListItemFieldValue.ToString().Split(';');
foreach (string s in indirizzi)
{
if (s != String.Empty)
{
try
{
SPFile file = spWeb.GetFile(s);
try
{
file.OpenBinary();
sb.Append("<a href=\"" + s + "\"> " + file.Name + " </a><br />");
}
catch (Exception exx)
{
}
}
catch (System.IO.FileNotFoundException exx)
{
sb.Append("<a href=\"" + s + "\"> " + s + " </a><br />");
}
}
}
}
HtmlGenericControl controllo = new HtmlGenericControl();
controllo.InnerHtml = sb.ToString();
this.Controls.Add(controllo);
}
}
}
protected override void Render(HtmlTextWriter output)
{
base.Render(output);
}
Do i have to change the OnRender? Thank you very much!!