2010-04-30 3 views
0

를이 코드를C# 및 추가 동적 META 태그

protected void Page_Load(object sender, EventArgs e) 
{ 
    DataSet.DestinationsDataTable GetDestinations = (DataSet.DestinationsDataTable)dta.GetData(); 
    Page.Title = GetDestinations.Rows[0]["Meta_Title"].ToString(); 

    HtmlMeta hm = new HtmlMeta(); 
    HtmlHead head = (HtmlHead)Page.Header; 
    hm.Name = GetDestinations.Rows[0]["Meta_Desc"].ToString(); 
    hm.Content = GetDestinations.Rows[0]["Meta_Key"].ToString(); 
    head.Controls.Add(hm); 
} 

을 그리고 (콘텐츠 페이지)

The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>). 

생각을이 오류를 반환이야?

답변

1

오류 메시지에서 명확하지 않은 부분이 표시되지 않습니다. <head> 태그에 <% %> 블록이 포함되어 있으므로 런타임에 컨트롤을 동적으로 추가 할 수 없습니다. 난 그냥 해결하는 방법을 알고하지 않았다 나는이 문제를 알고 감사를

protected void Page_Load(object sender, EventArgs e) 
{ 
    DataSet.DestinationsDataTable GetDestinations = (DataSet.DestinationsDataTable)dta.GetData(); 
    Page.Title = GetDestinations.Rows[0]["Meta_Title"].ToString(); 

    HtmlMeta hm = new HtmlMeta(); 
    hm.Name = GetDestinations.Rows[0]["Meta_Desc"].ToString(); 
    hm.Content = GetDestinations.Rows[0]["Meta_Key"].ToString(); 
    this.metaTags.Controls.Add(hm); 
} 
+0

아 :

는이 문제를 해결할 자리 표시자를 추가하고 거기 메타 태그를 넣어 :

<html> <head> ... <asp:PlaceHolder runat="server" ID="metaTags" /> </head> ... 

그리고 다음을 그것. 다시 한 번 감사드립니다! – balexander