Copying custom field value in a Work Item Custom Control in TFS2010
-
8 septembrie 2010 08:43
I have created a custom control for TWA, which has to show entered values of a custom field in it at various state changes. I mean the custom control should show all the revisions of custom field data together at once place. I am able to hold the text, but Text in custom control is repeating twice. Please check the code and suggest if any changes.
namespace CommentsControl
{
[ToolboxData("<{0}:CommentsControl runat=server></{0}:CommentsControl>")]
public class CommentsControl : WebControl, IWorkItemControl, IWorkItemWebControl//BaseWorkItemWebControl
{
#region Fields
private string m_label;
private string m_editorObject;
private string m_themeUrl;
private string m_controlId;
private System.Collections.Specialized.StringDictionary m_properties;
private bool m_readOnly;
private IServiceProvider m_site;
private string m_workItemFieldName;
private WorkItem m_dataSource;
private bool m_initialized = false;
private TextBox m_field;
public String commentsText;
public CommentsControl()
{
}
#region IWorkItemControl Members
private static object EventBeforeUpdateDatasource = new object();
public event EventHandler BeforeUpdateDatasource
{
add { Events.AddHandler(EventBeforeUpdateDatasource, value); }
remove { Events.RemoveHandler(EventBeforeUpdateDatasource, value); }
}
protected virtual void OnBeforeUpdateDatasource(EventArgs eventArgs)
{
EventHandler handler = (EventHandler)Events[EventBeforeUpdateDatasource];
if (handler != null)
{
handler.Invoke(this, eventArgs);
}
}
private static object EventAfterUpdateDatasource = new object();
public event EventHandler AfterUpdateDatasource
{
add { Events.AddHandler(EventAfterUpdateDatasource, value); }
remove { Events.RemoveHandler(EventAfterUpdateDatasource, value); }
}
public void Clear()
{
this.Value = "";
}
public void FlushToDatasource()
{
}
public void InvalidateDatasource()
{
this.m_field.Text = m_dataSource.Fields["Microsoft.VSTS.Common.SaveComments"].Value.ToString();
}
public System.Collections.Specialized.StringDictionary Properties
{
get
{
return m_properties;
}
set
{
m_properties = value;
}
}
public bool ReadOnly
{
get
{
return m_readOnly;
}
set
{
m_readOnly = value;
}
}
public void SetSite(IServiceProvider serviceProvider)
{
m_site = serviceProvider;
}
public object WorkItemDatasource
{
get { return m_dataSource; }
set
{
m_dataSource = (WorkItem)value;
if (m_dataSource != null)
{
m_dataSource.FieldChanged += new WorkItemFieldChangeEventHandler(WIChanged);
}
}
}
void WIChanged(object sender, WorkItemEventArgs e)
{
try
{
if (e.Field.ReferenceName == "Microsoft.VSTS.Common.Comment")
{
try
{
m_dataSource.Fields["Microsoft.VSTS.Common.SaveComments"].Value = m_dataSource.Fields["Microsoft.VSTS.Common.SaveComments"].Value + "\n" + m_dataSource.Fields["Microsoft.VSTS.Common.Comment"].Value.ToString();
}
catch { m_dataSource.Fields["Microsoft.VSTS.Common.SaveComments"].Value = ""; }
m_field.Text = "";}
}
catch { }
}
public string WorkItemFieldName
{
get
{
return m_workItemFieldName;
}
set
{
m_workItemFieldName = value;
}
}
#endregion
#region IWorkItemWebControl Members
public string ClientEditorObjectId
{
get
{
return m_label;
}
set
{
m_label = Label;
}
}
public string ClientObjectId
{
get;
set;
}
public string ControlId
{
get
{
return m_controlId;
}
set
{
m_controlId = value;
}
}
public string GetClientUpdateScript()
{
return string.Empty;
}
public void InitializeControl()
{
InitControl();
}
public string Label
{ get; set; }
public string ThemeUrl
{ get; set; }
public string Value
{
get
{
this.InitControl();
return m_field.Text;
}
set
{
this.InitControl();
m_field.Text = value;
}
}
private void InitControl()
{
if (m_initialized)
return;
base.Controls.Clear();
m_field = new TextBox();
m_field.ID = "Tab";
m_field.Text += new EventHandler(this.OnCheckedChanged); //"ABCDEDD";//
m_field.TextMode = TextBoxMode.MultiLine;
base.Controls.Add(m_field);
m_initialized = true;
}
void OnCheckedChanged(object sender, EventArgs e)
{
this.FlushToDatasource();
}
#endregion
}
}
Toate mesajele
-
9 septembrie 2010 05:40
H!
I got this worked. I have placed the below lines of code in Page.Postback.
if(!Page.IsPostBack)
{
if (e.Field.ReferenceName == "Microsoft.VSTS.Common.Comment")
{
try
{
m_dataSource.Fields["Microsoft.VSTS.Common.SaveComments"].Value = m_dataSource.Fields["Microsoft.VSTS.Common.SaveComments"].Value + "\n" + m_dataSource.Fields["Microsoft.VSTS.Common.Comment"].Value.ToString();
}
catch { m_dataSource.Fields["Microsoft.VSTS.Common.SaveComments"].Value = ""; }
m_field.Text = "";}
}
}
- Marcat ca răspuns de chanduvscMicrosoft Employee 9 septembrie 2010 05:40
-
9 martie 2012 18:58
Hi Chandu,
I am trying to create a custom web access work item control which has s dropdown which populates from another work item field value.
I believe there should be some post back involved to capture the value entered in the parent control however I am not able to get that using the standard code.
Can you throw soem light here?
Thanks
:D
-
9 martie 2012 19:55
Hi,
You may use some Java script to implement the scenario with in the code to handle the Java script. Could you please share me the code so that i can suggest any changes in it.
Thanks,
Chandu
-
12 martie 2012 20:47
Hi Chandu,
So my scenario is this -
I have two custom dropdown fields on the workitem
1. Project Cycle
2. Project Name
Now when a user selects project cycle, the project names should be populated from a service which returns all the projects based on the particular cycle.
I tried this on Team Explorer WI and could easily get it done but am stuck with the web one as it doesnt seem to fire a server side request when Project cycle is selected.
Can you tell me how you handled that?
Thanks
:D
-
13 martie 2012 21:43
Hey Chnadu,
So i resolved my issue with auto postback.
Dint realise we could use the standard event handlers on the web controls to manipulate the data populated.
Thanks anyways,
:D
- Propus ca răspuns de ApnCH 13 martie 2012 21:43