hello every one,
i am trying to add metatag to master page header from content page. My code goes like this.
string sn = ds.Tables[0].Rows[0]["MetaTitle"].ToString();
Literal lmeta = new Literal();
lmeta.Mode = LiteralMode.PassThrough;
lmeta.Text = string.Format("<meta name=\"Title\" content=\"{0}\"/>", sn);
this.Page.Header.Controls.Add(lmeta);
this.Page.Title = sn;
exactly at this line
this.Page.Header.Controls.Add(lmeta);
i am getting the following error.
The Controls collection cannot be modified because the control contains code blocks (i.e. <% ... %>).
i googled it but didn't solution for it.
My master page header goes like below.
<%@ Master Language="C#" AutoEventWireup="true" CodeFile="mMaster.master.cs" Inherits="m_mMaster" %>
<!DOCTYPE html>
<html lang="en">
<head id="Header" runat="server">
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" />
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css"
rel="stylesheet" type="text/css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap-theme.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"
even though if i put meta tag binding code in master page i am getting the same error. Please help me.