Show many images on asp.net page as thumbnails - asp.net

I have saved images uploaded by user in one of my folders.In the sql server DB I just save the file-name of the image. For one item I have nearly 5-6 images. So I have an itemID as one of the column and imagename as one column and i have 1 2 3 4 5 in the table.
I need to display all these images in thumbnail format on a page. Like on craigslist. How do i proceed?

You can use javascript/jQuery image box to display a large image with small thumbnails.
Here are the two I know -
FancyBox (I'm currently using)
LightBox
Or You can use the following code -
Demo at jsfiddle
<style type="text/css">
.container img {
width: 100px;
}
</style>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script>
$(document).ready(function () {
$(".container img").mouseover(function () {
$("#<%= LargeImage.ClientID %>").attr("src", $(this).prop('src'));
}).mouseout(function () {
$("#<%= LargeImage.ClientID %>").attr("src",
"http://placehold.it/400x400&text=Image1");
});
});
</script>
<asp:Image ID="LargeImage" ImageUrl="http://placehold.it/400x400&text=Image1"
runat="server" />
<div class="container">
<asp:Image ID="Image1" ImageUrl="http://placehold.it/400x400&text=Image2"
runat="server" />
<asp:Image ID="Image2" ImageUrl="http://placehold.it/400x400&text=Image3"
runat="server" />
<asp:Image ID="Image3" ImageUrl="http://placehold.it/400x400&text=Image4"
runat="server" />
<asp:Image ID="Image4" ImageUrl="http://placehold.it/400x400&text=Image5"
runat="server" />
</div>

Related

How to show a loading spinner when loading another aspx using asp.net and visual studio?

I know this question has been asked many times, but I didn't seem to find any solution that I can understand online. Most says using javaScript and css but I don't really know how to implement that.
I'm using visual studio and i have a master page and several other content pages. On the master page I have a link that redirects me to one of these content pages using
"a href = pages.aspx"
Since the content page uses a SQL query to retrieve data so it takes a very long time. I would like to show a loading spinner or progress bar or even just a text saying "loading..." while the page loads.
Are there anyway to do this?
I also thought about using a label which is only visible when the link is clicked, and goes invisible when the page loads. Is there a way of doing this?
Thanks!
An exact situation with detailed code and explanation, where a loading image is shown on loading of an asp.net page can be seen at following URL : Show Loading Image when Page first Loads.
This has detailed explanation with full working code as well as a link to demo page. You can ask me if you have any questions regarding this sample.
To verify that the loading image shows up in above sample you can simply go to this URL : Loading Image when Page first loads
Another very simple approach with tested/tried sample code is as explained below.
You will need jquery in your aspx page for this to work.
There are three scenarios in which you would like to show a loader element in an aspx page and they are:
On button click that does a non-ajax postback
hyperlink click that navigates to another page
on button click that does an ajax postback
In first two of above scenarios, all you need to do is hookup their client click event with a JavaScript method of ShowProgress. This method shows a popup div that has an animated image in it.
In the last scenario where an ajax postback is done, an UpdateProgress control is used so it automatically hides once the ajax postback completes.
The loader popup is styled to show at center of page in a modal manner'; these styles can be found in the head section of markup pasted below. You can modify some of these styles like border or background-color and also you can substitute any animated image in place of loading.gif.
I tested the markup below with a Page PageTakingLongToLoad.aspx that took 20 s to load the first time it rendered, and with ajax/non-ajax postbacks that took 10 s to complete, and in both cases the loader displayed perfectly as expected.
Markup of Page from which a loader is shown
<%# Page Language="C#" AutoEventWireup="true" CodeFile="InitialPage.aspx.cs" Inherits="InitialPage" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.modal {
position: fixed;
top: 0;
left: 0;
background-color: lightgray;
z-index: 99;
opacity: 0.8;
filter: alpha(opacity=80);
-moz-opacity: 0.8;
min-height: 100%;
width: 100%;
}
.loading {
font-family: Arial;
font-size: 10pt;
border: 5px dashed #f00;
width: 200px;
height: 100px;
display: none;
position: fixed;
background-color: White;
z-index: 999;
margin: 0 auto;
text-align: center;
padding-top: 35px;
}
</style>
<script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<div>
<div class="loading">
<div>
Loading. Please wait.<br />
<br />
<img src="loading.gif" alt="loading" />
</div>
</div>
Link To Another Page
<br /><br />
<asp:Button ID="btnPostBack" runat="server" OnClientClick="ShowProgress();" OnClick="btnPostBack_Click" Text="Do Long Process without Ajax" /><br /><br />
<asp:UpdatePanel ID="UpdatePanel1" runat="server" ChildrenAsTriggers="true">
<ContentTemplate>
<asp:Button ID="btnAjax" runat="server" OnClick="btnPostBack_Click" Text="Do Long Process with Ajax" />
</ContentTemplate>
</asp:UpdatePanel>
<asp:UpdateProgress ID="UpdateProgress1" runat="server" AssociatedUpdatePanelID="UpdatePanel1">
<ProgressTemplate>
<div class="loading" style="display: table">
<div>
Processing. Please wait...<br />
<br />
<img src="loading.gif" alt="loading" />
</div>
</div>
</ProgressTemplate>
</asp:UpdateProgress>
</div>
<script type="text/javascript">
function ShowProgress() {
setTimeout(function () {
var modal = $('<div />');
modal.addClass("modal");
$('body').append(modal);
var loading = $(".loading");
loading.css("vertical-align", "middle");
loading.css("display", "table-cell");
var top = Math.max($(window).height() / 2 - loading[0].offsetHeight / 2, 0);
var left = Math.max($(window).width() / 2 - loading[0].offsetWidth / 2, 0);
loading.css({ top: top, left: left });
}, 200);
}
</script>
</form>
</body>
</html>

Is it possible to auto increment repeater control?

I have a repeater control on my web page that displays images as a result of a search. The user searches for a keyword, and my program stores the search results in a data table. The repeater then displays the images in the data table. So, if there are 150 images in the data table, the repeater will display all 150 images. Here's the code for my repeater:
<div>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div style="background-color: Silver; border-style: solid; display: inline-block;
float: left; margin: 5px; overflow: hidden;">
<div style="text-align: center">
<asp:Label ID="lblImage" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "image") %>'></asp:Label>
</div>
<div>
<%# DataBinder.Eval(Container.DataItem, "url") %>
</div>
<div style="text-align: center;">
<asp:HyperLink ID="requestLink" runat="server" Text="Original" NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "requestUrl") %>'>
</asp:HyperLink>
</div>
</div>
</ItemTemplate>
</asp:Repeater>
</div>
What if, however, I don't want to display all 150 images? Is there a way to only display, say, 20 at a time and let the repeater auto expand when the user scrolls down or hits a 'MORE' button, or something like that?
Thanks!
For that you have to search for auto refresh or scroll event of mouse.
for auto refresh you can write this kind of code in javascript using that you can reload page after every interval
<script type="text/javascript">
setInterval(function () {
load()
}, 30000);
var load = function () {
location.reload();
};
</script>
and on Load event of page you have to rebind data to repeater.

Images not enlarging on click in asp.net

In my page I have a large image and set of small unit images. the large image will be loaded on page load. but when i click on small images it will get enlarge and get displayed in place of large image. the small images are displaying on page . but it has no effect on clicking them
here is my code
<div class="invDetailImage">
<img id="imgenlarge" src="" runat="server" alt="" align="middle" style="max-height:380px; max-width:579px; vertical-align:middle;"/>
<asp:Label runat="server" ID="lblerr" Visible="false" style="max-height:380px; max-width:579px; vertical-align:middle;font-size:large;"></asp:Label>
</div>
<!-- SMALL IMAGES -->
<div class="invDetailPhotoBox" runat="server" id="photobox">
<asp:Label runat="server" ID="lblphotos" Text="Select a photo below to view in the window above:"></asp:Label><br />
<asp:Repeater runat="server" ID="rptrinventoryphotos" onitemdatabound="rptrinventoryphotos_ItemDataBound">
<ItemTemplate>
<img id="imgInventory" src="" runat="server" alt='<%#Eval("ImagePath")%>' style="display:none;" />
<div onclick="large('<%#Eval("ImagePath")%>')" style="float:left;clear:none; margin-left:-12px;">
<asp:Image ID="Image1" Visible="true" runat="server" />
</div>
</ItemTemplate>
</asp:Repeater>
</div>
<script type="text/javascript"> function large(src) {
var str=src; document.getElementById("ctl00_ContentPlaceHolder1_imgenlarge").src = (str);
}
function loading(img) { img.src = "images/loading.gif"; }
</script>
protected void rptrinventoryphotos_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
HtmlImage img1 =(HtmlImage) e.Item.FindControl("imgInventory");
Image img = (Image)e.Item.FindControl("Image1");
img.ImageUrl = "http://localhost:22525/DWLive/ImageResizeHandler.ashx?imgPath=" + img1.Alt + "&width=75&height=56";
img.Style.Add("margin-left", "-12px");
img.Style.Add("background-image", "url('images/loading9.gif')");
img.Style.Add("background-repeat", "no-repeat");
img.Style.Add("background-position", "center left");
//img.Attributes.Add("onclick", "large('" + img1.Alt + "')");
string[] a = img1.Alt.Split((#"/").ToCharArray());
}
can anyone help please? thanks.
The problem was in JavaScript. I changed it to:
<script type="text/javascript">
function large(link) {
var str = link;
}
document.getElementById("ctl00_ContentPlaceHolder1_imgenlarge").src = (str);

asp.net page not scrolling

Here is my problem:
<asp:Panel ID="pnlMyAddressBook" runat="server" BackColor="White" CssClass="roundcorner">
TEST<table style="width: 100%;">
Do I need to explain that the page doesn't scroll to show the list of all the validation errors?
Its a panel being shown on a modal popup... I have tried setting the height property for the panel... no use...
Also, including this (required) Jquery function in the HTML causes the panel to move to a corner... I have removed it for now from my HTML...
<script type="text/javascript">
$(function () {
$("#tabs").tabs();
});
C# code for the button opening the modal:
protected void btnEdit_Click(object sender, EventArgs e)
{
ClientScript.RegisterStartupScript(this.GetType(), "key", "launchModalV2();", true);
//ClearTextBoxes();
PopUpAddressInLightBox();
mpeTest.Show();
hdnfld.Value = "Edit";
}
HTML
<asp:Button ID="btnEdit" runat="server" Text="Edit Address pb" OnClick="btnEdit_Click" CssClass="btn" />
<asp:Button ID="btnAddNew" runat="server" Text="Add New Address pb" OnClick="btnAddNew_Click" />
I am using these 2 buttons to call the modal....
.modalBackground
{
background-color: Black;
-filter: alpha(opacity=80);
-opacity: 0.6;
z-index: 10000;
}
In the css of your modal popup, set the width of the modalpop up, then set the overflow:auto. That will give you vertical scrollbar. Example:
.ModalPopupPanel
{
height:700px;
overflow:auto;
}
So,when the content height exceed the 700px, the horizontal scrollbar will show up. The same is true for the horizontal scrollbar where you need to set the width of the modalpop.

Using a validator callout extender with FCKEditor does not set "left" style

As it says in the title, I'm doing custom validation with FCK (because the RequiredFieldValidator doesn't work with FCKEditor). When validation fails, the callout appears, but it does not show up in the correctposition.
Generated style tag: visibility: visible; position: absolute; left: 0px; top: 646px; z-index: 1000;
Not that left is coming as 0px. (The top isn't quite right either, but it's close enough for now)
Here's my markup:
<FCKeditorV2:FCKeditor ID="FCKeditorBody" runat="server" Width="600" Height="150" ToolbarSet="Basic"></FCKeditorV2:FCKeditor>
<asp:CustomValidator runat="server" ID="cvBody" ControlToValidate="FCKeditorBody" SetFocusOnError="true"
ErrorMessage="Please enter a body." ClientValidationFunction="ValidateBody" ValidateEmptyText="true"
ValidationGroup="ValgrpPost" Display="None" />
<asp:ValidatorCalloutExtender runat="Server" ID="ValidatorCalloutExtender7" BehaviorID="vceBID" TargetControlID="cvBody"
HighlightCssClass="ValidatorCalloutHighlightCSS" CssClass="RecipeCalloutCSS" PopupPosition="TopLeft" />
<script type="Text/javascript">
function ValidateBody(source, args) {
var fckBody = FCKeditorAPI.GetInstance('<%=FCKeditorBody.ClientID %>');
args.IsValid = fckBody.GetXHTML(true) != "";
}
</script>
Make sure you put an element with position:relative around the FCKeditor and the validator, then it will show at the top left of the FCKeditor.
<div style="position:relative">
<FCKeditorV2:FCKeditor ... />
<asp:CustomValidator ... />
<asp:ValidatorCalloutExtender ... />
<script type="text/javascript">
function ValidateBody(source, args) {
var fckBody = FCKeditorAPI.GetInstance('<%=FCKeditorBody.ClientID %>');
args.IsValid = fckBody.GetXHTML(true) != "";
}
</script>
</div>
The message will now cover the toolbar and block the buttons untill you press the "x". A backgroundcolor should be added to the message to make it better visible.
If you wanted to show it inside the textarea of the editor, maybe PopupPosition="BottomRight" is better for that. Or you could overrule the generated css with an !important rule.
.RecipeCalloutCSS{ left:0!important; top:65px!important; }

Resources