how can i use a asp:hyperlink in my code where the user can press the number and go to another page, so this is my code,
if (dt != null)
{
foreach (DataRow dr in dt.Rows)
{
loggedin.Text = "Registered users today: " + dr["RegisteredUsersToday"];
}
if (dtParent != null)
{
foreach (DataRow dr in dtParent.Rows)
{
loggedinParents.Text = "Registered Parents today: " + dr["RegisteredUsersToday"];
}
}
else
{
loggedinParents.Text = "Registered Parents today: 0 ";
}
if (dtTeacher != null)
{
foreach (DataRow dr in dtTeacher.Rows)
{
loggedinTeachers.Text = "Registered Teachers today: " + dr["RegisteredUsersToday"];
}
}
else
{
loggedinTeachers.Text = "Registered Teachers today: 0 ";
}
if (dtStudents != null)
{
foreach (DataRow dr in dtStudents.Rows)
{
loggedinStudents.Text = "Registered Students today: " + dr["RegisteredUsersToday"];
}
}
else
{
loggedinStudents.Text = "Registered Students today: 0 ";
}
}
else
{
loggedin.Text = "No new users today";
}
i want the hyperlink to be between RegisteredUsersToday, and this is my html where a have created the labels,
<div class="panel panel-default">
<div class="text-center panel-heading">
<a data-toggle="collapse" href="#collapse1" >
<asp:Label runat="server" ID="loggedin"></asp:Label>
</a>
</div>
<br />
<div id="collapse1" class="panel-collapse collapse">
<div class="text-center">
<asp:Label runat="server" ID="loggedinParents"></asp:Label>
</div>
<br />
<div class="text-center">
<asp:Label runat="server" ID="loggedinTeachers"></asp:Label>
</div>
<br />
<div class="text-center">
<asp:Label runat="server" ID="loggedinStudents"></asp:Label>
</div>
</div>
</div>
Related
It is such that I have a Repeater with both label and Literal content, and that is how I got it into Repeater and I would like it being like shown at the side.
It appears with the error that tells me that it can not find my label or Literal
Repeater her:
<asp:Repeater ID="RepeaterOpslag" runat="server">
<ItemTemplate>
<div id="forslagbox" runat="server">
<asp:Label ID="LabelBrugernavn" runat="server"></asp:Label>
<asp:Literal ID="LiteralLikesOpslag" runat="server"></asp:Literal>
<asp:Literal ID="LiteralDelete" runat="server"></asp:Literal>
<div style="margin-bottom: 5px; clear: both;"></div>
<asp:Label ID="LabelText" runat="server"></asp:Label>
<div style="margin-top: 5px; clear: both;"></div>
<div class="col-md-12">
<hr class="tall" style="margin: 7px 0;">
</div>
</div>
</ItemTemplate>
</asp:Repeater>
Default.aspx.cs here, It is in foreach which gives me problems that it will not print any of it at all.
RepeaterOpslag.DataSource = db.ForslagOpslags.ToList();
RepeaterOpslag.DataBind();
List<ForslagOpslag> forslagopslag = db.ForslagOpslags.ToList();
foreach (ForslagOpslag item in forslagopslag)
{
var likesFjern = db.ForslagOpslagLikes.Where(a => a.fk_brugerid == Helper.ReturnBrugerId()).Count();
LabelBrugernavn.Text = item.brugere.fornavn + " " + item.brugere.efternavn;
LabelText.Text = item.text;
if (likesFjern >= 1)
{
LiteralLikesOpslag.Text = "<a href='fjernsynesgodtom.aspx?id=" + item.Id + "&brugerid=" + Helper.ReturnBrugerId() + "' class='btn btn-danger btn-xs'>Fjern synes godt om</a>";
}
else if (item.brugere.Id != Helper.ReturnBrugerId())
{
LiteralLikesOpslag.Text = "<a href='SynesGodtOm.aspx?id=" + item.Id + "' class='btn btn-success btn-xs'>Like opslag - " + item.ForslagOpslagLikes.Count() + " synes godt om</a>";
}
else
{
LiteralLikesOpslag.Text = "<p class='label label-lg label-success'>" + item.ForslagOpslagLikes.Count() + " synes godt om</p>";
}
if ((item.fk_brugerid == Helper.ReturnBrugerId() || Helper.BrugerRank(Helper.ReturnBrugerId()) == 1))
{
LiteralDelete.Text = "<a href='slet.aspx?id=" + item.Id + "' class='btn btn-danger btn-xs'>Slet</a>";
}
}
How can I get all tweets on behalf of specific hashtag/keyword and display it on View page? The only solution found returns a null exception.
public ActionResult TweetView(string txtTwitterName)
{
//TwitterService("consumer key", "consumer secret");
var service = new TwitterService("", "");
//AuthenticateWith("Access Token", "AccessTokenSecret");
service.AuthenticateWith("", "");
TwitterSearchResult tweets = service.Search(new SearchOptions { Q = txtTwitterName, SinceId=29999 });
IEnumerable<TwitterStatus> status = tweets.Statuses;
ViewBag.Tweets = tweets;
return View();
}
View :
IEnumerable<TwitterStatus> tweets = ViewBag.Tweets as IEnumerable<TwitterStatus>;
foreach (var tweet in tweets)
{
<div class="tweet">
<div class="picture">
<img src="#tweet.User.ProfileImageUrl" alt="#tweet.User.ScreenName" title="#tweet.User.ScreenName" />
</div>
<div class="info">
<span>#tweet.User.Name, #tweet.User.Description - #tweet.User.Location </span>
<br />
<a href="https://twitter.com/statuses/#tweet.Id" class="text">
#tweet.Text
</a>
<div class="action">
#tweet.CreatedDate.AddHours(3).ToString("d/M/yyyy HH:mm:ss")
</div>
</div>
<div class="clear">
</div>
</div>
}
for the null value, in your view :
IEnumerable<TwitterStatus> status = ViewBag.Tweets as IEnumerable<TwitterStatus>;
if(status != null )
{
foreach (var tweet in status)
{
<div class="tweet">
<div class="picture">
<img src="#tweet.User.ProfileImageUrl" alt="#tweet.User.ScreenName"
title="#tweet.User.ScreenName" />
</div>
<div class="info">
<span>#tweet.User.Name, #tweet.User.Description - #tweet.User.Location </span>
<br />
<a href="https://twitter.com/statuses/#tweet.Id" class="text">
#tweet.Text
</a>
<div class="action">
#tweet.CreatedDate.AddHours(3).ToString("d/M/yyyy HH:mm:ss")
</div>
</div>
<div class="clear">
</div>
</div>
}
}
and for your Controller, modify the last code by :
ViewBag.Tweets = status;
I hope this post will help, thx :)
I struggled with the same problem. Here is my vague solution. The function will return whenever your required number of tweets are returned. I hope it helps you.
string maxid = "1000000000000"; // dummy value
int tweetcount = 0;
if (maxid != null)
{
var tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count) });
List<TwitterStatus> resultList = new List<TwitterStatus>(tweets_search.Statuses);
maxid = resultList.Last().IdStr;
foreach (var tweet in tweets_search.Statuses)
{
try
{
ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
tweetcount++;
}
catch { }
}
while (maxid != null && tweetcount < Convert.ToInt32(count))
{
maxid = resultList.Last().IdStr;
tweets_search = twitterService.Search(new SearchOptions { Q = keyword, Count = Convert.ToInt32(count), MaxId = Convert.ToInt64(maxid) });
resultList = new List<TwitterStatus>(tweets_search.Statuses);
foreach (var tweet in tweets_search.Statuses)
{
try
{
ResultSearch.Add(new KeyValuePair<String, String>(tweet.Id.ToString(), tweet.Text));
tweetcount++;
}
catch { }
}
}
}
In Below code I used repeater control and i want to get value from dropdownlist on linkbutton click that is inside the repeater. In below code when i click on button then dropdownlist is return first value.
Please reply as soon as possible Thanks in advance.
ASP.NET MARKUP
<asp:Repeater ID="rptProduct" runat="server" OnItemCommand="rptProduct_ItemDataBound">
<ItemTemplate>
<div class="span6">
<h3><%# Eval("ProductName")%>
</h3>
<hr class="soft" />
<form class="form-horizontal qtyFrm">
<div class="control-group">
<label class="control-label">
<span>Select Quantity</span>
</label>
<div class="controls">
<asp:DropDownList ID="ddlQuantity" class="span1" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
<asp:LinkButton ID="lnkAddCart" runat="server" class="btn btn-large btn-primary pull-right" CommandName="Add">Add to cart
<i class=" icon-shopping-cart"></i>
</asp:LinkButton>
</div>
</div>
<asp:Label ID="lblError" Visible="false" class="alert alert-block alert-error" runat="server" Text=""></asp:Label>
</form>
<hr class="soft clr" />
<p><%#Eval("Description")%>
</p>
<a class="btn btn-small pull-right" href="#detail">More Details</a>
<br class="clr" />
<hr class="soft" />
</div>
</ItemTemplate>
</asp:Repeater>
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
rptCategory.DataSource = bll.getCategory();
rptCategory.DataBind();
if (Request.QueryString["productID"] != null)
{
BindDataList();
bindcartdetail();
}
}
}
protected void rptProduct_ItemDataBound(object sender, RepeaterCommandEventArgs e)
{
DropDownList ddlQuantity = (DropDownList)e.Item.FindControl("ddlQuantity");
Label lblError = ((Label)e.Item.FindControl("lblError"));
Image photo = (Image)e.Item.FindControl("imgProduct");
if (e.CommandName == "Add")
{
string qty = ddlQuantity.SelectedValue;
Session["proQty"] = qty;
Session["photo"] = photo.ImageUrl;
cart();
}
}
protected void cart()
{
int productID = Convert.ToInt32(Request.QueryString["productID"]);
DataTable dtproduct = new DataTable();
dtproduct = bll.getProductbyID(productID);
string proCode = dtproduct.Rows[0][3].ToString();
string proName = dtproduct.Rows[0][4].ToString();
int quantity = Convert.ToInt32(Session["proQty"]);
string photo = Session["photo"].ToString();
// SESSION ID
SessionIDManager manager = new SessionIDManager();
string OldID = Context.Session.SessionID;
if (OldID == "")
{
string sessionid = manager.CreateSessionID(Context);
bool redirected = false;
bool isAdded = false;
manager.SaveSessionID(Context, sessionid, out redirected, out isAdded);
Session["sessionid"] = sessionid;
Session["proid"] = productID;
Session["proCode"] = proCode;
Session["proname"] = proName;
DataTable dtinfo = new DataTable();
dtinfo = bll.getCartInfo(proCode, sessionid);
// PRODUVT IS AVLB OR NOT
if (dtinfo.Rows.Count > 0)
{
int proquantity = Convert.ToInt32(dtinfo.Rows[0][3].ToString());
proquantity = proquantity + quantity;
bll.updateCart(proquantity, proCode, sessionid);
Response.Redirect("Product.aspx");
}
else
{
bll.addCart(proCode, proName, quantity, sessionid, photo);
Response.Redirect("Product.aspx");
}
}
else
{
string sessionid = OldID;
Session["sessionid"] = sessionid;
Session["proid"] = productID;
Session["proCode"] = proCode;
Session["proname"] = proName;
DataTable dtinfo = new DataTable();
dtinfo = bll.getCartInfo(proCode, sessionid);
if (dtinfo.Rows.Count > 0)
{
int proquantity = Convert.ToInt32(dtinfo.Rows[0][3].ToString());
proquantity = proquantity + quantity;
bll.updateCart(proquantity, proCode, sessionid);
Response.Redirect("Product.aspx");
}
else
{
bll.addCart(proCode, proName, quantity, sessionid, photo);
Response.Redirect("Product.aspx");
}
}
}
<div class="controls">
<asp:DropDownList ID="ddlQuantity" class="span1" runat="server">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:DropDownList>
<asp:LinkButton ID="lnkAddCart" runat="server" class="btn btn-large btn-primary pull-right" OnClick="lnkAddCart_click">Add to cart <i class=" icon-shopping-cart"></i> </asp:LinkButton>
</div>
I have an product order review page that displays a list of whatever the user has entered. What is needed is the name of the location that each product or product grouping belongs to (i.e. If the user selected 3 products from under the "Desks" listing, those three products should appear under the header "Desks" on the order review page. If the user purchased 5 items from under the "Lobbies" listing, then those 5 products should appear under the header "Lobbies" on the order review page).
Currently, I can get the correct header text, but the text repeats itself with each item (i.e. The header "Desks" appears above each of the 3 items ordered under the "Desks" listing). I would like it to appear only once per item/grouping of items but I am not sure how to do it.
I am using a repeater to display the order information to the user, and everything else is working the way I want it. It's just this little bit I'm confused about. Any help would be great. Thanks in advance!
Here is the designer code:
<asp:Repeater ID="orderRepeater" runat="server" >
<itemtemplate>
<h3 class="locationName"><%# Eval("LocationName") %></h3>
<div class="headerRow">
<div class="header">
<div class="thumb"><p></p></div>
<div class="headerField name"><p class="hField">Product</p></div>
<div class="headerField sku"><p class="hField">GOJO SKU</p></div>
<div class="headerField size"><p class="hField">Size</p></div>
<div class="headerField case"><p class="hField">Case Pack</p></div>
<div class="headerField qty"><p class="hField">Quantity</p></div>
</div>
</div>
<div class="table">
<div class="row">
<div class="thumb"><%# Eval("Thumbnail") %></div>
<div class="field name"><p class="pField"> <%#Eval("ProductName") %> </p></div>
<div class="field sku"><p class="pField"> <%#Eval("Sku") %></p></div>
<div class="field size"><p class="pField"> <%#Eval("Size") %></p></div>
<div class="field case"><p class="pField"><%#Eval("CasePack") %></p></div>
<div class="field qty"><p class="pField"><%#Eval("Qty") %></p></div>
</div>
</div>
</itemtemplate>
</asp:Repeater>
Here is the code behind:
private void Page_Load(object sender, EventArgs e)
{
Label lbl = (Label)FindControl("orderLbl");
Item CurrentItem = Sitecore.Context.Item;
Item HomeItem = ScHelper.FindAncestor(CurrentItem, "gojoMarket");
if (Session["orderComplete"] != null && Session["orderComplete"] != "")
{
if (HomeItem != null)
{
Item ProductGroup = HomeItem.Axes.SelectSingleItem(#"child::*[##templatename='gojoMarketOfficeBuildigProductMap']/*[##templatename='gojoOrderReview']");
Database db = Sitecore.Context.Database;
DataSet dset = new DataSet();
if (ProductGroup != null)
{
string InFromSession = Session["orderComplete"].ToString();
try
{
DataTable summary = dset.Tables.Add("summary");
summary.Columns.Add("LocationName", Type.GetType("System.String"));
summary.Columns.Add("Thumbnail", Type.GetType("System.String"));
summary.Columns.Add("ProductName", Type.GetType("System.String"));
summary.Columns.Add("Sku", Type.GetType("System.String"));
summary.Columns.Add("Size", Type.GetType("System.String"));
summary.Columns.Add("CasePack", Type.GetType("System.String"));
summary.Columns.Add("Qty", Type.GetType("System.String"));
summary.Columns.Add("Location", Type.GetType("System.String"));
Label qL = (Label)FindControl("qty");
string[] orders = InFromSession.Split(';');
foreach (string order in orders)
{
int total = orders.GetUpperBound(0);
if (order != "")
{
string[] infos = order.Split(',');
string ids = infos.GetValue(0).ToString();
string qtys = infos.GetValue(1).ToString();
if (ids != "")
{
Item CatalogueItem = db.Items[ids];
DataRow drow = summary.NewRow();
Item LocationItem = ScHelper.FindAncestor(CatalogueItem, "gojoProductLocation");
if (LocationItem != null)
{
//this returns the header text values that I need
string LocationName = LocationItem.Fields["Header"].ToString();
drow["LocationName"] = LocationName;
}
Item orderItem = db.Items[CatalogueItem.Fields["Reference SKU"].Value];
if (orderItem != null)
{
Item marketItem = db.Items[orderItem.Fields["Master Product"].Value];
if (marketItem != null)
{
Item CPNItem = db.Items[marketItem.Fields["Complete Product Name"].Value];
drow["Thumbnail"] = "";
Sitecore.Data.Fields.XmlField fileField = marketItem.Fields["Thumbnail"];
drow["Thumbnail"] = "<image src=\"" + ScHelper.GetCorrectFilePath(fileField) + "\" border=\"0\" alt=\"\">";
if (CPNItem != null)
{
var name = CPNItem["Complete Name"];
drow["ProductName"] = name;
}
drow["Sku"] = marketItem.Fields["SKU"].Value;
drow["CasePack"] = marketItem.Fields["Case Pack"].Value;
if (marketItem.Fields["Size"] != null)
{
drow["Size"] = marketItem.Fields["Size"].Value;
}
else
{
drow["Size"] = "N/A";
}
drow["Qty"] = qtys.ToString();
summary.Rows.Add(drow);
}
}
}
}
}
orderRepeater.DataSource = dset;
orderRepeater.DataMember = "summary";
orderRepeater.DataBind();
}
catch (Exception x)
{
Response.Write(x.Message.ToString());
}
}
}
}
else
{
HyperLink none = (HyperLink)FindControl("link");
Label msg = (Label)FindControl("msgLbl");
none.Visible = true;
msg.Text = "You have not selected any items for purchase. To purchase items, please visit our complete product listing: ";
}
}
I'd put the header in the <HeaderTemplate>. So it'd look like:
<asp:Repeater ID="orderRepeater" runat="server" >
<HeaderTemplate><h3><asp:Literal runat="server" id="header" /></h3></HeaderTemplate>
<ItemTemplate>[your existing code here]</ItemTemplate>
</asp:Repeater>
And in code behind do something like:
protected void orderRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Header)
{
((Literal)e.Item.FindControl("header")).Text = "The header" // Whatever you would like this to be;
}
}
in a strange situation my page_Load Runs twice and all of my codes are in page_Load.
i can not use Page.IsPostBac because in both of Page_Loads, it is false.
but what is strange situation ?
i have a page for download files in my project,
when you click on one of download links (i used anchors, so IsPostBack is false) page_Load runs and in page load i check DownloadPath Querystring.
if DownloadPath not be null i jump to a Handler.ashx by passing that DownloadPath for showing Download Window To My Users.
during this process i have some logs in my database and because of that twice running they will be duplicate.
but when twice running accours ?
when you try to download a link by internet download manager, page_Load runs twice!
how can i prevent second runing of page_Load or is there a way for recognize it?
EDIT :
my page_Load :
namespace NiceFileExplorer.en
{
public partial class Download : System.Web.UI.Page
{
public string Folders = "";
public string Files = "";
protected void Page_Load(object sender, EventArgs e)
{
Statistics_body_inside.DataBind();
if (Request.QueryString["Path"] != null)
{
if (Request.QueryString["Path"] == "..")
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "YouCanNotDoThatAnyMore", "YouCanNotDoThatAnyMore();", true);
}
else
{
MainCodes();
}
}
else
{
MainCodes();
}
}
private void MainCodes()
{
if (Request.QueryString["DownloadPath"] != null)
{
string DownloadPath = Request.QueryString["DownloadPath"].ToString();
string FilePath = "C:" + DownloadPath.Replace(#"/", #"\\");
if (Session["User_ID"] != null)
{
string FileName = Request.QueryString["FileName"].ToString();
string FileSize = Request.QueryString["FileSize"].ToString();
string FileCreationDate = Request.QueryString["FileCreationDate"].ToString();
int Downloaded_Count_4Today = DataLayer.Download.Count_By_UserID_Today(int.Parse(HttpContext.Current.Session["User_ID"].ToString()), DateTime.Now);
if (Downloaded_Count_4Today <= 10)
{
DataSet dsDownload = DataLayer.Download.Size_By_UserID_Today(int.Parse(HttpContext.Current.Session["User_ID"].ToString()), DateTime.Now);
if (dsDownload.Tables["Download"].Rows.Count > 0)
{
DataRow drDownload = dsDownload.Tables["Download"].Rows[0];
int SumOfFileSize4Today = int.Parse(drDownload["FileSizSum"].ToString());
if (SumOfFileSize4Today + int.Parse(FileSize) <= 1073741824)//1 GB = 1024*1024*1024 bytes = 1073741824 bytes
//if (SumOfFileSize4Today + int.Parse(FileSize) <= 100000)
{
//DataLayer.Download.InsertRow(
// int.Parse(Session["User_ID"].ToString()),
// DateTime.Now,
// FilePath.Replace(#"\\", #"\"),
// FileName,
// FileSize,
// DateTime.Parse(FileCreationDate)
// );
Response.Redirect("~/HandlerForMyFE.ashx?Downloadpath=" + HttpUtility.UrlEncode(DownloadPath));
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "YouCanNotDownloadAnyMore_SizeOverload", "YouCanNotDownloadAnyMore_SizeOverload();", true);
}
}
else
{
if (int.Parse(FileSize) <= 1073741824)
//if (int.Parse(FileSize) <= 100000)
{
//DataLayer.Download.InsertRow(
// int.Parse(Session["User_ID"].ToString()),
// DateTime.Now,
// FilePath.Replace(#"\\", #"\"),
// FileName,
// FileSize,
// DateTime.Parse(FileCreationDate)
// );
Response.Redirect("~/HandlerForMyFE.ashx?Downloadpath=" + HttpUtility.UrlEncode(DownloadPath));
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "YouCanNotDownloadAnyMore_SizeOverload", "YouCanNotDownloadAnyMore_SizeOverload();", true);
}
}
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "YouCanNotDownloadAnyMore_CountOverload", "YouCanNotDownloadAnyMore_CountOverload();", true);
}
}
else
{
ScriptManager.RegisterStartupScript(this.Page, typeof(Page), "plzLoginFirst_ForDownload", "plzLoginFirst_ForDownload();", true);
}
}
DirectoryInfo dir;
string lastpath = "";
try
{
lastpath = Request["path"].ToString();
}
catch { }
lblTitleInHeader.Text = "Files";
lblTitleInHeader.Text += lastpath;
//set back
string[] splited = lblTitleInHeader.Text.Split('/');
lblTitleInHeader.Text = "";
ArrayList arName = new ArrayList();
for (int i = 0; i < splited.Length; i++)
{
if (splited[i] != "")
{
arName.Add(splited[i]);
}
}
for (int i = 0; i < arName.Count - 1; i++)
{
if (i != arName.Count - 1)
{
lblTitleInHeader.Text += "<a href='Download.aspx?path=%2f";//%2f = /
for (int j = 1; j < i + 1; j++)
{
lblTitleInHeader.Text += HttpUtility.UrlEncode(arName[j].ToString() + "/");
}
lblTitleInHeader.Text += "'>" + arName[i] + "</a>" + " " + "<img class='icoSubFolder' src='../Images/Download/icoSubFolder.png' />";
}
}
lblTitleInHeader.Text += arName[arName.Count - 1].ToString();
lblTitleInHeader.Text = lblTitleInHeader.Text.Replace("/'>", "'>");
if (lastpath != "")
{
//dir = new DirectoryInfo(Server.MapPath("~/Files/" + lastpath));
dir = new DirectoryInfo(#"C:\\Files\\" + lastpath.Replace(#"/", #"\\"));
}
else
{
//dir = new DirectoryInfo(Server.MapPath("~/Files/"));
dir = new DirectoryInfo(#"C:\\Files\\");
}
int count4Folders = 0;
foreach (DirectoryInfo d in dir.GetDirectories())
{
count4Folders++;
DirectoryInfo dirSub = new DirectoryInfo(d.FullName);
int iDir = 0;
int iFile = 0;
foreach (DirectoryInfo subd in dirSub.GetDirectories())
{
iDir++;
}
foreach (FileInfo f in dirSub.GetFiles("*.*"))
{
iFile++;
}
Folders += "<div class='divFoldersBody_Row'>";
Folders += "<div class='divFoldersBody_Left'>";
Folders += " ";
Folders += "</div>";
Folders += "<div class='divFoldersBody_Name'>";
Folders += "<span class='imgFolderContainer'><img class='imgFolder' src='../Images/Download/folder.png' /></span>";
Folders += "<span class='FolderName'><a class='FolderLink' href='Download.aspx?path=" + HttpUtility.UrlEncode(lastpath + "/" + d.Name) + "'>";
Folders += d.Name;
Folders += "</a></span>";
Folders += "</div>";
Folders += "<div class='divFoldersBody_Count'>";
Folders += iDir.ToString() + " Folders & " + iFile.ToString() + " Files";
Folders += "</div>";
Folders += "<div class='divFoldersBody_Right'>";
Folders += " ";
Folders += "</div>";
Folders += "</div>";
}
if (count4Folders == 0)
{
divFoldersHeader.Style.Add("display", "none");
}
int count4Files = 0;
foreach (FileInfo f in dir.GetFiles("*.*"))
{
count4Files++;
Files += "<div class='divFilesBody_Row'>";
Files += "<div class='divFilesBody_Left'>";
Files += " ";
Files += "</div>";
Files += "<div class='divFilesBody_Name'>";
char[] Extension_ChAr = f.Extension.ToCharArray();
string Extension_str = string.Empty;
int lenghth = Extension_ChAr.Length;
for (int i = 1; i < Extension_ChAr.Length; i++)
{
Extension_str += Extension_ChAr[i];
}
if (Extension_str.ToLower() == "rar" || Extension_str.ToLower() == "zip" || Extension_str.ToLower() == "zipx" || Extension_str.ToLower() == "7z" || Extension_str.ToLower() == "cat")
{
Files += "<span class='imgFileContainer'><img class='imgFile-rar' src='../Images/Download/file-rar.png' /></span>";
}
else if (Extension_str.ToLower() == "txt" || Extension_str.ToLower() == "doc" || Extension_str.ToLower() == "docx")
{
Files += "<span class='imgFileContainer'><img class='imgFile-txt' src='../Images/Download/file-txt.png' /></span>";
}
else if (Extension_str.ToLower() == "pdf")
{
Files += "<span class='imgFileContainer'><img class='imgFile-pdf' src='../Images/Download/file-pdf.png' /></span>";
}
else if (Extension_str.ToLower() == "jpg" || (Extension_str.ToLower() == "png") || (Extension_str.ToLower() == "gif") || (Extension_str.ToLower() == "bmp") || (Extension_str.ToLower() == "psd"))
{
Files += "<span class='imgFileContainer'><img class='imgFile-image' src='../Images/Download/file-image.png' /></span>";
}
else if (Extension_str.ToLower() == "exe")
{
Files += "<span class='imgFileContainer'><img class='imgFile-exe' src='../Images/Download/file-exe.png' /></span>";
}
else
{
Files += "<span class='imgFileContainer'><img class='imgFile-unknown' src='../Images/Download/file-unknown.png' /></span>";
}
Files += "<span title='" + f.Name + "' class='FileName'>";
Files += f.Name;
Files += "</span>";
Files += "</div>";
Files += "<div class='divFilesBody_FileType'>";
Files += "<span style='color:red;'>" + Extension_str.ToUpper() + "</span>" + " File";
//Files += Path.GetExtension(f.Name) + " File";
Files += "</div>";
Files += "<div class='divFilesBody_FileSize'>";
Files += ConvertBytes.ToFileSize(long.Parse(f.Length.ToString()));
Files += "</div>";
Files += "<div class='divFilesBody_FileCreationDate'>";
Files += f.CreationTime;
Files += "</div>";
Files += "<div class='divFilesBody_FileDownload'>";
string Downloadpath = "/Files" + lastpath + "/" + f.Name;
string EncodedDownloadpath = HttpUtility.UrlEncode(Downloadpath);
Files += "<a class='FileLink' href='Download.aspx?path=" + HttpUtility.UrlEncode(lastpath) + "&Downloadpath=" + EncodedDownloadpath + "&FileName=" + HttpUtility.UrlEncode(f.Name) + "&FileSize=" + HttpUtility.UrlEncode(f.Length.ToString()) + "&FileCreationDate=" + HttpUtility.UrlEncode(f.CreationTime.ToString()) + "'>";
Files += "<img class='imgDownload' src='../Images/Download/Download.png' />";
Files += "</a>";
Files += "</div>";
Files += "<div class='divFilesBody_Right'>";
Files += " ";
Files += "</div>";
Files += "</div>";
}
if (count4Files == 0)
{
divFilesHeader.Style.Add("display", "none");
}
if ((count4Folders == 0) && (count4Files == 0))
{
divFoldersHeader.Style.Add("display", "block");
divFilesHeader.Style.Add("display", "block");
}
ScriptManager.RegisterStartupScript(this, this.GetType(), "hash", "location.hash = '#BreadCrumbInDownload';", true);
}
....
my aspx :
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<link href="css/Download.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
$(function () {
$('#Download-body *').css({ 'zIndex': 2 });
$('#Download-body').css({ 'overflow': 'hidden', 'position': 'relative' });
var containerWidth = $('#Download-body').innerWidth();
var containerHeight = $('#Download-body').innerHeight();
var bgimgurl = $('#Download-body').css('backgroundImage').replace(/url\(|\)|"|'/g, "");
var img = $('<img src="' + bgimgurl + '" width="' + containerWidth + 'px"' + ' height="' + containerHeight + 'px" />').css({ 'position': 'absolute', 'left': 0, 'top': 0, 'zIndex': 1 });
$('#Download-body').css({ 'background': 'transparent' }).append(img);
});
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<div id="Download">
<div id="Download-header">
<div id="DownloadTitle">
Download
</div>
<asp:Image ID="imgDownload_header_left" runat="server" ImageUrl="~/Images/Download-header-left.png" />
<asp:Image ID="imgDownload_header_right" runat="server" ImageUrl="~/Images/Download-header-right.png" />
</div>
<div id="Download-body">
<div id="Download-body-inside">
<div id="Statistics">
<div id="Statistics-header">
<div id="StatisticsTitle">
Statistics
</div>
<asp:Image ID="imgStatistics_header_left" runat="server" ImageUrl="~/Images/Statistics-header-left.png" />
<asp:Image ID="imgStatistics_header_right" runat="server" ImageUrl="~/Images/Statistics-header-right.png" />
</div>
<div id="Statistics-body">
<div runat="server" id="Statistics_body_inside">
<asp:Label ID="lblDownload_Count_By_UserID_Title" runat="server" Text="Ur Download Count :"
ToolTip="Your Download Count From The Begining Of Registration UpTo Now" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Count_By_UserID" runat="server" Text="<%# Download_Count_By_UserID() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Count_By_UserID_Today_Title" runat="server" Text="Ur Download Count-Today :"
ToolTip="Your Download Count-Today" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Count_By_UserID_Today" runat="server" Text="<%# Download_Count_By_UserID_Today() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Size_By_UserID_Title" runat="server" Text="Ur Download Size :"
ToolTip="Your Download Size From The Begining Of Registration UpTo Now" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Size_By_UserID" runat="server" Text="<%# Download_Size_By_UserID() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Size_By_UserID_Today_Title" runat="server" Text="Ur Download Size-Today :"
ToolTip="Your Download Size-Today" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Size_By_UserID_Today" runat="server" Text="<%# Download_Size_By_UserID_Today() %>"
CssClass="lblCountInStatistics"></asp:Label>
<br />
<asp:Label ID="lblDownload_Size_By_UserID_Today_Remain_Title" runat="server" Text="Ur Remain Download Size-Today :"
ToolTip="Your Remain Download Size-Today" CssClass="lblTitleInStatistics"></asp:Label>
<asp:Label ID="lblDownload_Size_By_UserID_Today_Remain" runat="server" Text="<%# Download_Size_By_UserID_Today_Remain() %>"
CssClass="lblCountInStatistics"></asp:Label>
</div>
</div>
</div>
<div id="MainDivInDownload">
<div id="BreadCrumbInDownload">
<div id="imgicoHomeContainer">
<asp:Image ID="imgicoHome" runat="server" ImageUrl="~/Images/Download/icoHome.png" />
</div>
<div id="lblTitleInHeaderContainer">
<asp:Label ID="lblTitleInHeader" runat="server" Text=""></asp:Label>
</div>
<div style="clear: both;">
</div>
</div>
<div runat="server" id="divFolders">
<div runat="server" id="divFoldersHeader">
<div id="divFoldersHeader_Left">
<asp:Image ID="divFoldersHeader_imgLeft" runat="server" ImageUrl="~/Images/Download/divsHeader_Left.png" />
</div>
<div id="divFoldersHeader_Name">
Folders In This Folder
</div>
<div id="divFoldersHeader_Count">
Total Files In This Folder
</div>
<div id="divFoldersHeader_Right">
<asp:Image ID="divFoldersHeader_imgRight" runat="server" ImageUrl="~/Images/Download/divsHeader_Right.png" />
</div>
</div>
<div id="divFoldersBody">
<%-- <div class="divFoldersBody_Row">
<div class="divFoldersBody_Left">
</div>
<div class="divFoldersBody_Name">
<span class="imgFolderContainer">
<asp:Image CssClass="imgFolder" runat="server" ImageUrl="~/Images/Download/folder.png" />
</span><span class="FolderName"><a class="FolderLink" href="#">Folders In This Folder</a></span>
</div>
<div class="divFoldersBody_Count">
Total Files In This Folder
</div>
<div class="divFoldersBody_Right">
</div>
</div>--%>
<%= Folders %>
</div>
</div>
<div runat="server" id="divFiles">
<div runat="server" id="divFilesHeader">
<div id="divFilesHeader_Left">
<asp:Image ID="divFilesHeader_imgLeft" runat="server" ImageUrl="~/Images/Download/divsHeader_Left.png" />
</div>
<div id="divFilesHeader_Name">
Files In This Folder
</div>
<div id="divFilesHeader_FileType">
File Type
</div>
<div id="divFilesHeader_FileSize">
File Size
</div>
<div id="divFilesHeader_FileCreationDate">
File Creation Date
</div>
<div id="divFilesHeader_FileDownload">
</div>
<div id="divFilesHeader_Right">
<asp:Image ID="divFilesHeader_imgRight" runat="server" ImageUrl="~/Images/Download/divsHeader_Right.png" />
</div>
</div>
<div id="divFilesBody">
<%-- <div class="divFilesBody_Row">
<div class="divFilesBody_Left">
</div>
<div class="divFilesBody_Name">
<span class="imgFileContainer">
<asp:Image runat="server" ImageUrl="~/Images/Download/file.png" CssClass="imgFile" />
</span><span class="FileName">Files In This Folder</span>
</div>
<div class="divFilesBody_FileType">
File Type
</div>
<div class="divFilesBody_FileSize">
File Size
</div>
<div class="divFilesBody_FileCreationDate">
File Creation Date
</div>
<div class="divFilesBody_FileDownload">
<a class="FileLink" href="#">
<asp:Image CssClass="imgDownload" runat="server" ImageUrl="~/Images/Download.png" />
</a>
</div>
<div class="divFilesBody_Right">
</div>
</div>--%>
<%= Files %>
</div>
</div>
</div>
</div>
</div>
</div>
</asp:Content>
thanks in advance
Please look at the html as it is rendered on the page:
Every time it's present
<img src=""/>
double postback can happen, for some browser...
If this is the trouble, you can resolve it setting a default, blank, image for every button
<asp:ImageButton ImageUrl="~/Images/blank.gif"...