J'essaie d'utiliser du javascript sur une mise en page, et je rencontre un problème étrange où le ClientID d'un Sharepoint.WebControls.TextField semble changer entre OnLoad et la page affichée.SharePoint TextField ClientID change-t-il?
En cas OnLoad, TextField3.ClientID décide « ctl00_PlaceHolderMain_TextField3 », mais si regarder pour voir pourquoi mes js ne fonctionne pas, la page source révèle que l'ID de commande à « ctl00_PlaceHolderMain_TextField3_ctl00_TextField ».
Des idées? Que se passe-t-il?
Voici le code que je utilise:
public class PostingTemplate : Microsoft.SharePoint.Publishing.PublishingLayoutPage
{
protected DropDownList author;
protected TextField TextField3;
private List<string> _authorNames;
public List<string> AuthorName
{
get { return _authorNames; }
set { _authorNames = value; }
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
author.AutoPostBack = false;
this.Page.ClientScript.RegisterClientScriptBlock(this.GetType(),
"fillInAuthorText", getQuery(), true);
author.Attributes.Add("onChange", "fillInAuthorText()");
if (!Page.IsPostBack)
{
_authorNames = new List<string>();
_authorNames = Utilities.GetAuthorList(SPContext.Current.Site);
author.DataSource = _authorNames;
author.DataBind();
}
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (author.Items.Count > 0)
{
author.SelectedIndex = 0;
TextField3.Text = ((ListItem)author.Items[author.SelectedIndex]).Text;
}
}
private string getQuery()
{
string query = @" function fillInAuthorText() {
var IndexValue = document.getElementById('";
query += author.ClientID;
query += @"').selectedIndex;
var SelectedVal = document.getElementById('";
query += author.ClientID;
query += @"').options[IndexValue].value;
document.getElementById('";
query += TextField3.ClientID;
query += @"').value = SelectedVal;
}";
return query;
}
}