{"id":827,"date":"2010-09-03T01:41:22","date_gmt":"2010-09-02T20:11:22","guid":{"rendered":"http:\/\/JitendraZaa.com\/blog\/?p=827"},"modified":"2010-09-03T01:41:22","modified_gmt":"2010-09-02T20:11:22","slug":"add-css-programatically-in-asp-net","status":"publish","type":"post","link":"https:\/\/www.jitendrazaa.com\/blog\/webtech\/add-css-programatically-in-asp-net\/","title":{"rendered":"Add CSS Programatically in ASP.NET"},"content":{"rendered":"<p>We Can set (Register) the Javascript file in ASP.NET but there is no such method for the CSS. So i have decided to write the article on how to set the CSS path dynamically in ASP.NET and C#.<\/p>\n<p><!--more--><\/p>\n<p>To achieve, just add <strong>runat <\/strong>attribute in link tag and access it at code behind.<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;head&gt;\n&lt;link id=&quot;commonStyleSheet&quot; rel=&quot;stylesheet&quot; type=&quot;text\/css&quot; runat=&quot;server&quot; \/&gt;\n&lt;\/head&gt;\n<\/pre>\n<p>after this, in Page Load method just add attribute <strong>href <\/strong>as shown below.<\/p>\n<p><strong>VB Code:<\/strong><\/p>\n<pre class=\"brush: vb; title: ; notranslate\" title=\"\">\nSub Page_Load(Sender As Object, E As EventArgs)\n If Not (IsPostBack)\n    commonStyleSheet.Attributes.Add(&quot;href&quot;,&quot;http:\/\/ www.JitendraZaa.com \/blog \/CommonStylesheet.css&quot;)\n End If\nEnd Sub\n<\/pre>\n<p><strong>C# Code:<\/strong><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nprotected void Page_Load(object sender, EventArgs e)\n{\n commonStyleSheet.Attributes.Add(&quot;href&quot;, &quot;https:\/\/www.jitendrazaa.com\/blog\/CommonStylesheet.css&quot;);\n}\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Tutorial on adding the CSS file dynamically in ASP.NET and C# \/ VB.Net<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"jz_research_post":"","_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[21,19],"tags":[43,67],"class_list":["post-827","post","type-post","status-publish","format-standard","hentry","category-net","category-webtech","tag-asp-net","tag-css"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack-related-posts":[{"id":1343,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/telerik-controls-css-lost-on-page-postback\/","url_meta":{"origin":827,"position":0},"title":"Telerik Controls &#8211; CSS Lost on Page Postback","author":"Jitendra","date":"November 9, 2010","format":false,"excerpt":"Telerik Controls - CSS Lost on Page Postback in Chrome and Mozilla firefox","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2299,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/tutorial-read-and-export-excel-file-in-asp-net-using-c\/","url_meta":{"origin":827,"position":1},"title":"Tutorial &#8211; Read and export excel file in ASP.Net  using C#","author":"Jitendra","date":"July 29, 2011","format":false,"excerpt":"Tutorial - Read and export excel file in ASP.Net using C#","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Read And Export Excel in ASP.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/07\/Read-And-Export-Excel-in-ASP.Net_.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1527,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/ajax-based-multiselect-jquery-autocomplete-control-in-asp-net\/","url_meta":{"origin":827,"position":2},"title":"Ajax Based Multiselect JQuery Autocomplete Control in ASP.Net","author":"Jitendra","date":"February 19, 2011","format":false,"excerpt":"Tutorial on creating Ajax Based Multiselect JQuery Autocomplete User Control in ASP.Net","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Ajax Based Multiselect JQuery Autocomplete Control in ASP.Net","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/02\/Ajax-Based-Multiselect-JQuery-Autocomplete-Control-in-ASP.Net_.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":2395,"url":"https:\/\/www.jitendrazaa.com\/blog\/others\/tips\/asp-net-page-lifecycle\/","url_meta":{"origin":827,"position":3},"title":"ASP.NET Page Lifecycle","author":"Jitendra","date":"August 24, 2011","format":false,"excerpt":"Tutorial and sample source code on ASP.NET Page Lifecycle","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Control hierarchy after page_init() event in asp.net page life cycle","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2011\/08\/Control-hierarchy-after-page_init-event-in-asp.net-page-life-cycle.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":608,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/selecting-and-sorting-in-datatable-asp-net-c\/","url_meta":{"origin":827,"position":4},"title":"Selecting and Sorting in DataTable &#8211; ASP.net C#","author":"Jitendra","date":"July 7, 2010","format":false,"excerpt":"Demonstrates that how to select and sort the Datatable in ASP.Net , C#","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"Sorting and Selecting DataTable in ASP","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/07\/Sorting-and-Selecting-DataTable-in-ASP-300x223.png?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":191,"url":"https:\/\/www.jitendrazaa.com\/blog\/microsoft\/net\/datagrid-example-part-1\/","url_meta":{"origin":827,"position":5},"title":"DataGrid Example &#8211; Part 1","author":"Jitendra","date":"May 18, 2010","format":false,"excerpt":"For the basics of DataGrid please refer this post: https:\/\/jitendrazaa.com\/blog\/?p=188 In this example, i will explain the basics of DataGrid control like Theming, Databinding etc. We will start our example with creating the SQL Express database of Employee which will contain the following fields : Id, FName, LName, Email. Now\u2026","rel":"","context":"In &quot;ASP.NET&quot;","block_context":{"text":"ASP.NET","link":"https:\/\/www.jitendrazaa.com\/blog\/category\/microsoft\/net\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/jitendrazaa.com\/blog\/wp-content\/uploads\/2010\/05\/Employee.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/827","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/comments?post=827"}],"version-history":[{"count":0,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/posts\/827\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/media?parent=827"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/categories?post=827"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jitendrazaa.com\/blog\/wp-json\/wp\/v2\/tags?post=827"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}