UncleCoder.com

UncleCoder.com

Free programming examples and instructions

Asp.net - Linking CSS to routed URL

Demo and Code for how to link CSS file to routed URL

by Athil


Posted on 24 Jun 2019 Category: Asp.net Views: 54

Edited on 24 Jun 2019


Here I am going to show to Add CSS and Javascript to routed URL Web application in asp.net.

DEMO

<!--CSS Linking-->
<link rel ="stylesheet" href="<%=  ResolveUrl("~/") %>css/bootstrap.min.css"/> 
<!-- Script Linking -->
<script type="text/javascript" src="<%= ResolveUrl("~/") %>js/jquery.min.js" ></script>


Where ResolveUrl() is the server function will return the full URL of the website.

Full Demo code 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="css-javascript-routed-url.aspx.cs" Inherits="recaptcha.css_javascript_routed_url" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>Demo for adding CSS and javascript to Routed URL</title>


    <link rel ="stylesheet" href="<%=  ResolveUrl("~/") %>css/bootstrap.min.css"/> 
     <script type="text/javascript" src="<%= ResolveUrl("~/") %>js/jquery.min.js" ></script>




</head>
<body>
   
    <div>
    <h1> Demo for how to add CSS and javascript to Routed URL </h1>
      <h4 id="h4">Bootstrap Button Click The button to change the text of h4</h4> 
        <button class="btn btn-primary" onclick="jQueryEvent();">Click Here </button>

    </div>
 



   

</body>
    <script>
        function jQueryEvent()
        {
            $("#h4").html("Text Changed");
        }
        </script>
</html>

In this Demo, we added jQuery script to change the text and bootstrap css to style button. 



Leave a Comment: