Я пытаюсь использовать некоторый JavaScript на макете страницы, и я сталкиваюсь со странной проблемой, когда ClientID для Sharepoint.WebControls.TextField, кажется, меняется между OnLoad и отображаемой страницей.
В событии OnLoad TextField3.ClientID преобразуется в «ctl00_PlaceHolderMain_TextField3», но если посмотреть, почему мой js не работает, источник страницы обнаружит, что идентификатором элемента управления является «ctl00_PlaceHolderMain_TextField3_ctl00_TeF».
Есть идеи, что происходит?
Вот код, который я использую:
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;
}
}