Free programming examples and instructions

Asp.net - Linking javascript to routed URL web application

Demo and code for how to link javascript and CSS files to routed URL Websites in Asp.net

by Athil

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

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


<!-- Script Linking -->
<script type="text/javascript" src="<%= ResolveUrl("~/") %>js/jquery.min.js" ></script>

<!--CSS Linking-->
<link rel ="stylesheet" href="<%=  ResolveUrl("~/") %>css/bootstrap.min.css"/> 

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>

    <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>



        function jQueryEvent()
            $("#h4").html("Text Changed");

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

Leave a Comment:

Click here to register

Popular articles