Decrease Font Size
Increase Font Size
   BLOG

Creating Custom ASP.NET Server Controls with Embedded JavaScript and Style Sheet and Images

Creating Custom ASP.NET Server Controls with Embedded JavaScript and Style Sheet and Images

Embedding JavaScript in ASP.NET

Embedding Style Sheet in ASP.NET

Embedding Images in ASP.NET

 

Right click one of the images, select Properties, and change the Build Action value from Content to Embedded Resource. Repeat the same step for all the other images.

 Embed Images

Repeat the above step for the JavaScript and Style Sheet.

Double click the AssemblyInfo.cs. Add the following to the bottom of the file.

 
[assembly: System.Web.UI.WebResource("MyTextScroller.TextScroller.css", "text/css")]
[assembly: System.Web.UI.WebResource("MyTextScroller.TextScroller.js", "text/javascript")]
[assembly: System.Web.UI.WebResource("MyTextScroller.images.nav-arrow-down-hover.gif", "image/gif")]
[assembly: System.Web.UI.WebResource("MyTextScroller.images.nav-arrow-down.gif", "image/gif")]
[assembly: System.Web.UI.WebResource("MyTextScroller.images.nav-arrow-up-hover.gif", "image/gif")]
[assembly: System.Web.UI.WebResource("MyTextScroller.images.nav-arrow-up.gif", "image/gif")]

Note:

Default Namespace

The syntax - [assembly: System.Web.UI.WebResource("Default Namespace.File Location.File Name", "Type")]

Example 1

My Default Name Space is MyTextScroller

My JavaScript File name is TextScroller.js

And I’ll end up having this line in my AssemblyInfo.cs

[assembly: System.Web.UI.WebResource("MyTextScroller.TextScroller.js", "text/javascript")]

Example 2

My Default Name Space is MyTextScroller

My image is in images folder

My image name is nav-arrow-down-hover.gif

And I’ll end up having this line in my AssemblyInfo.cs

[assembly: System.Web.UI.WebResource("MyTextScroller.images.nav-arrow-down.gif", "image/gif")]