Advertisement Slider With Javascript + ASP.Net
There is a inbuilt control name Add Rotator of displaying adds on a page. But it cause postback to displaye next add. So here is a an Add Rotator like code in asp.net and javascript. jaavscript is used ot rotate adds one after another. This is the basic concept and idea. You can do more from this.
Content Needed:-
Images in the image folder.
A script file to rotate the adds and Asp.net coding.
script is in the demo download link at the end of the topic.
Below is the code:-
ASPX Page Code (.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Javscript Advertisements</title>
<script type="text/javascript" language="javascript" src="script/slidecontent.js">
</script>
</head>
<body>
<form id="form1" runat="server">
<ul id="offersList" runat="server" style="display:none;"></ul>
<div id="offers" style="width:400px; height:220px;">
<script type="text/javascript" language="javascript">
getItems();
</script>
</div>
</form>
</body>
</html>
Content Needed:-
Images in the image folder.
A script file to rotate the adds and Asp.net coding.
script is in the demo download link at the end of the topic.
Below is the code:-
ASPX Page Code (.aspx)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Javscript Advertisements</title>
<script type="text/javascript" language="javascript" src="script/slidecontent.js">
</script>
</head>
<body>
<form id="form1" runat="server">
<ul id="offersList" runat="server" style="display:none;"></ul>
<div id="offers" style="width:400px; height:220px;">
<script type="text/javascript" language="javascript">
getItems();
</script>
</div>
</form>
</body>
</html>
.cd Page Code
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Collections;
using System.Text;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
GetAllFiles();
}
private void GetAllFiles()
{
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/images"));
FileInfo[] file = dir.GetFiles();
string[] lst = new string[3];
lst[0] = "First Add";
lst[1] = "Second Add";
lst[2] = "Third Add";
string str = "";
for (int i = 0; i < file.Length; i++)
{
str += "<li><b>" + lst[i].ToString() + "</b><br>" + "<img src='images\\" + file[i].Name.ToString();
str += "' alt='" + Path.GetFileNameWithoutExtension(file[i].ToString()) +"' /></li>";
}
offersList.InnerHtml = str.ToString();
}
}
In the above code I use String array for the add content and image directly from the folder. You can use this concept by accessing the content and image path from the database also. Just you need to fill the dataset or datatable and create add one by one in a loop.
Download the complete working code form the link below:-
https://docs.google.com/open?id=0B2iokvd3EpXANTA1YWZlYjktYjc1Zi00N2VkLWEyZWMtZTE0NGRiYjZkODNk
https://docs.google.com/open?id=0B2iokvd3EpXANTA1YWZlYjktYjc1Zi00N2VkLWEyZWMtZTE0NGRiYjZkODNk
Very Interesting Share...
ReplyDeleteThanks For this...
Please give Some Topics Related to Sql Server
ReplyDeleteThanks Lot
@ Swati: Sure. I m thinking about this..
ReplyDeleteOk i ll do
Okey Thanks ....
ReplyDelete