Live Chat Icon For mobile
Live Chat Icon

How to set a <link> tag’s href attribute at runtime using a value specified in the web.config file

Platform: ASP.NET| Category: Miscellaneous

web.config


<configuration>
   	<appSettings>
		<add key='CSS1' value='StyleSheet1.css' />
	</appSettings>
</configuration>

.aspx


<link id='link1' runat='server'/>

VB.NET


Dim lnk As New System.Web.UI.HtmlControls.HtmlGenericControl('lnk')
lnk = CType(Me.Page.FindControl('link1'), System.Web.UI.HtmlControls.HtmlGenericControl)
lnk.Attributes.Add('rel', 'stylesheet')
lnk.Attributes.Add('href', ConfigurationSettings.AppSettings('CSS1').ToString())
lnk.Attributes.Add('type', 'text/css')

C#


System.Web.UI.HtmlControls.HtmlGenericControl  lnk =new System.Web.UI.HtmlControls.HtmlGenericControl ('lnk')    ;
lnk =(System.Web.UI.HtmlControls.HtmlGenericControl ) this.Page.FindControl( 'link1') ;
lnk.Attributes.Add  ('rel', 'stylesheet'); 
lnk.Attributes.Add ('href', ConfigurationSettings.AppSettings['CSS1'].ToString()) ;
lnk.Attributes.Add ('type','text/css');

Share with

Share on twitter
Share on facebook
Share on linkedin

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.