Showing posts with label images. Show all posts
Showing posts with label images. Show all posts

Wednesday, March 28, 2012

Modal Popup Extender ?

I have created a table programatically which displays images from the database in thumbail fashion.

for (int i = 1; i <= rows; i++) {// Create a new row and add it to the table. TableRow tRow =new TableRow(); Table1.Rows.Add(tRow);for (int j = 0; j < cells; j++) {if (count >= 0) {// Create a new cell and add it to the row. TableCell tCell =new TableCell(); tRow.Cells.Add(tCell); HyperLink link =new HyperLink(); link.NavigateUrl ="~/" + images[count].FullImage; link.ImageUrl ="~/" + images[count].ThumbnailImage; tCell.Controls.Add(link); tCell.Controls.Add(new LiteralControl("<br><br><b>Title</b> : " + getproducts[count].Name +"<br>"));/*Add Checkout and add to cart Images */ HyperLink wishlistLink =new HyperLink(); wishlistLink.ImageUrl="~\\images\\Add_to_wish_list.gif"; HyperLink checkoutLink =new HyperLink(); checkoutLink.ImageUrl ="~\\images\\Add_to_my_cart.gif";/*Add the Images to the cells*/ tCell.Controls.Add(wishlistLink); tCell.Controls.Add(checkoutLink); } } }

Now I want when user clicks on thumbnail it opens a modal popup extender and displays the full image with some other information. Someone can please let me know how to do it programatically using the Hyperlink I have ?

This should give you what you needed

link.Target="_blank";

http://www.startvbdotnet.com/aspsite/controls/linkbutton.aspx


You could have the hyperlink post back and then in the code behind call ModalPopupExtender1.Show() if you really need it to pop in a modal extender. Make sure to wrap you code that will be posting back inside an update panel for the best user experience.


Hi Thukralz,

thukralz:

Now I want when user clicks on thumbnail it opens a modal popup extender and displays the full image with some other information. Someone can please let me know how to do it programatically using the Hyperlink I have ?

You should create ModalPopupExtender and its associated Panel dynamically for each HyperLink and set the ModalPopupExtender's properties on the server side. But I don't think it is a good way for its low perfermance. The improved method is that we only use one ModalPopupExtender in a page and the ModalPopupExtender is activated when the HyperLink is fired by using Javascript functions.

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"></script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Change Picture</title> <style> .modalBackground { background-color:Gray; filter:alpha(opacity=70); opacity:0.7; } .modalPopup { background-color:#FFD9D5; border-width:3px; border-style:solid; border-color:Gray; padding:3px; width:250px; } </style></head><body> <form id="form1" runat="server"> <div> <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <asp:Image ID="Image1" runat="server" ImageUrl="~/pic/upg_Business.jpg" imgUrl="../pic/upg_HomePremium.jpg" onclick="changePicture(event.srcElement.imgUrl)"/><asp:Image ID="Image2" runat="server" ImageUrl="~/pic/upg_HomeBasic.jpg" imgUrl="../pic/upg_Ultimate.jpg" onclick="changePicture(event.srcElement.imgUrl)"/> <asp:Panel ID="Panel1" runat="server" CssClass="modalPopup" Height="200px" Width="300px" style="display:none"> <asp:Image ID="Image3" runat="server" ImageUrl="~/pic/AJAX.gif"/> <asp:Button ID="Button2" runat="server" Text="Cancel" /> </asp:Panel> <ajaxToolkit:ModalPopupExtender ID="ModalPopupExtender1" runat="server" TargetControlID="Button1" PopupControlID="Panel1" CancelControlID="Button2"> </ajaxToolkit:ModalPopupExtender> <div style="display:none"> <asp:Button ID="Button1" runat="server" Text="Button" /> </div> <script type="text/javascript" language="javascript"> function changePicture(imgUrl){ $get("<%=Image3.ClientID%>").src = imgUrl; $get("<%=Button1.ClientID%>").click(); } </script> </div> </form></body></html>
I hope this help.
Best regards,
Jonathan

Saturday, March 24, 2012

Modal Popup Question ?

I create a table programatically which displays images from the database in thumbail fashion.

for (int i = 1; i <= rows; i++) {// Create a new row and add it to the table. TableRow tRow =new TableRow(); Table1.Rows.Add(tRow);for (int j = 0; j < cells; j++) {if (count >= 0) {// Create a new cell and add it to the row. TableCell tCell =new TableCell(); tRow.Cells.Add(tCell); HyperLink link =new HyperLink(); link.NavigateUrl ="~/" + images[count].FullImage; link.ImageUrl ="~/" + images[count].ThumbnailImage; tCell.Controls.Add(link); tCell.Controls.Add(new LiteralControl("<br><br><b>Title</b> : " + getproducts[count].Name +"<br>"));/*Add Checkout and add to cart Images */ HyperLink wishlistLink =new HyperLink(); wishlistLink.ImageUrl="~\\images\\Add_to_wish_list.gif"; HyperLink checkoutLink =new HyperLink(); checkoutLink.ImageUrl ="~\\images\\Add_to_my_cart.gif";/*Add the Images to the cells*/ tCell.Controls.Add(wishlistLink); tCell.Controls.Add(checkoutLink); } } }
Now I want when user clicks on thumbnail it opens a modal popup extender and displays the full image with some other information . How this can be achieved ?

For something like this, I would recommendLighbox or aCSS only implementation. Both are geared specifically for graphics and are nice effects. However, take a look here:http://mattberseth.com/blog/2007/07/modalpopupextender_example_cre.html for how to use the ModalPopup for an image viewer.

-Damien


Hello Damien,

I was wondering for the lightbox, it says to activate you need rel="lightbox". My Question is as I'm creating the link and putting pictures programatically how that can be achieved.

Code snippet will be really appreciated.

Thanks,

Harsimrat


To add the rel attribute all you need to do is to assign the attribute using the Attributes.Add method. For example:

HyperLink link =new HyperLink();
link.Attributes.Add("rel", "lightbox");

-Damien


Hello Damien,

When I do something like this :

HyperLink link =newHyperLink();

//link.NavigateUrl ="~/" + images[count].FullImage;

link.ImageUrl ="~/" + images[count].ThumbnailImage;

//link.Attributes.Add("onclick", "ShowModalPopup('" + images[count].FullImage + "')");

link.Attributes.Add("a href","" + images[count].FullImage);

link.Attributes.Add("rel","lightbox");

1) Everything is shown at the end of the page with a close button, for some reason not as a javascript. Can you please let me know where I'm going Wrong.

2) Is there any way to show some extra buttons or pictures with the picture shown ?

3) And how can I adjust the Height and Width of the Image using link control ?

Thanks for your help.


In terms of rendering, are you doing this as part of your original code? For example (I shortened it up a bit):
...for (int j = 0; j < cells; j++)
{
// Create a new cell and add it to the row.
TableCell tCell =new TableCell();
tRow.Cells.Add(tCell);

HyperLink link =new HyperLink();
link.NavigateUrl ="~/" + images[count].FullImage;
link.ImageUrl ="~/" + images[count].ThumbnailImage;
link.Attributes.Add("rel", "lightbox");
...

Also, link.Attributes.Add("a href","" + images[count].FullImage); isn't correct. The attribute would behrefnota href, although your NavigateUrl will take care of this so you can exclude it.

In regards to your questions "Is there any way to show some extra buttons or pictures with the picture shown ?", you can add other controls to the cell. The HyperLink is a single control, if you want to add a button, you would need to add an asp:button. Not sure if this answers your question...

For sizing, look at the Width and Height properties; see:http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlink_properties.aspx

Hope this helps.

-Damien


For the second question, I should have been more clearer. When the lighbox opens I want to show stuff by its side as by default it only allows Title .


Oh, sorry. I'm not sure if you can add controls to the lightbox. I'm sure you can work something out to get that to work if you need to by modifying the JavaScript source, but the design of lightbox is simplicity (e.g. just showing a caption)

-Damien

Wednesday, March 21, 2012

ModalPopup + Gridview + images

Hello Guys!!! First I'm sorry for my englishEmbarrassed

I found this code in this forum and I try for see images from gridview and modalpopup, but, the images in gridview is clickable and i can go inside the panel, in this panel I want see the image big, but in gridview I have image small.

Any idea or some script different?

Thank you some much!!!!

<%@dotnet.itags.org.PageLanguage="C#"AutoEventWireup="true"CodeFile="Default2.aspx.cs"Inherits="Default2" %><!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><scriptrunat="server">

protectedvoid Page_Load(object sender,EventArgs e){

//Attach a Javascript funtion to the GridViewRow.

GridViewRow myGridViewRow;

for (int i = 0; i < GridView1.Rows.Count; i++){

myGridViewRow = (GridViewRow)GridView1.Rows[i];myGridViewRow.Attributes.Add("onclick","shopModalPopup('" + GridView1.Rows[i].Cells[0].Text +"');return false;");

}

}

</script><htmlxmlns="http://www.w3.org/1999/xhtml"><headid="Head1"runat="server"><title>Untitled Page</title>

<style>

.modalBackground {background-color:Gray;filter:alpha(opacity=70);opacity:0.7;}

.modalPopup {background-color:#FFD9D5;border-width:3px;border-style:solid;border-color:Gray;padding:3px;width:250px;}

</style></head><body><formid="form1"runat="server"><ajaxToolkit:ToolkitScriptManagerID="ScriptManager1"runat="server"></ajaxToolkit:ToolkitScriptManager>

<asp:GridViewID="GridView1"runat="server"AutoGenerateColumns="False"DataKeyNames="id_product"

DataSourceID="SqlDataSource1">

<Columns>

<asp:BoundFieldDataField="id_product"HeaderText="id_product"InsertVisible="False"ReadOnly="True"SortExpression="img_b">

<ItemStyleWidth="0px"/>

</asp:BoundField>

<asp:BoundFieldDataField="titolo"HeaderText="titolo"SortExpression="titolo"/>

<asp:BoundFieldDataField="numero"HeaderText="numero"SortExpression="numero"/>

<asp:BoundFieldDataField="colore"HeaderText="colore"SortExpression="colore"/>

<asp:TemplateField>

<ItemTemplate>

<asp:ImageButtonID="LinkButton1"runat="server"ImageUrl='<%# Eval("img_s") %>'/>

</ItemTemplate>

</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:SqlDataSourceID="SqlDataSource1"runat="server"ConnectionString="<%$ ConnectionStrings:cn_superexport %>"ProviderName="<%$ ConnectionStrings:cn_superexport.ProviderName %>"SelectCommand="SELECT * FROM [product]"></asp:SqlDataSource>

<asp:PanelID="Panel1"runat="server"CssClass="modalPopup"Height="200px"Width="300px"style="display:none">

<asp:UpdatePanelID="UpdatePanel1"runat="server">

<ContentTemplate>

EmployeeID:<asp:TextBoxID="tbEmployeeID"runat="server"></asp:TextBox><br/>

image:<asp:ImageID="image"runat="server"ImageUrl='<%# Eval("img_s") %>'></asp:image>

</ContentTemplate>

</asp:UpdatePanel>

<asp:ButtonID="btnCancel"runat="server"Text="Cancel"/>

</asp:Panel>

<divstyle="display: none">

<asp:ButtonID="Button1"runat="server"Text="Button"/></div>

<ajaxToolkit:ModalPopupExtenderID="ModalPopupExtender1"runat="server"TargetControlID="Button1"

PopupControlID="Panel1"CancelControlID="btnCancel"BackgroundCssClass="modalBackground">

</ajaxToolkit:ModalPopupExtender>

<scripttype="text/javascript"language="javascript">

function shopModalPopup(id_product){

//show the ModalPopupExtender

$get("<%=tbEmployeeID.ClientID %>").value = id_product;$find("<%=ModalPopupExtender1.ClientID %>").show();

}

</script></form></body></html>

Hello,

Is it that you want the image in panel1, which is the same as the image in the grid, to be full sized when it pops up?

If so, try to specify a width and height for the image in panel1.

<asp:ImageID="image"Width="200px"Height="440px"runat="server"ImageUrl='<%# Eval("img_s") %>'></asp:image>

Thanks,

Louis


Thank you for solution but still not work. Maybe I need different script...What you think? You have some solution?

Guys is possible click in button image from gridview and this open ModalPopupExtender for see the same image but more big, so different filed?

Please Help me!!


OK,

I think I have something for you. I used the gridview image example on MSDN :http://msdn2.microsoft.com/en-us/library/aa479350.aspx to make my grid.

Basically, I use javascript to add a click event to the row when the grid binds. You could do it on the image itself, its pretty straightforward.

When you click the row, I get the image path and put that path into the image inside the modal panel, where the image size is expanded, then I show the modal.

ASPX Page:

<%@.PageLanguage="C#"AutoEventWireup="true"CodeFile="LousTest.aspx.cs"Inherits="TestPages_LousTest" %>

<%@.RegisterAssembly="AjaxControlToolkit"Namespace="AjaxControlToolkit"TagPrefix="cc1" %>

<!DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<htmlxmlns="http://www.w3.org/1999/xhtml">

<headrunat="server">

<title>Untitled Page</title>

<scripttype="text/javascript">

function onSelect(elem) {

var sc = elem.cells[3].children[0].src;

//put this src path inot the images src...

var imager = document.getElementById("Image1");

imager.src = sc;

$find('a_modal').show();

}

</script>

</head>

<body>

<formid="form1"runat="server">

<asp:ScriptManagerID="sc1"runat="server"/>

<div>

<asp:GridViewID="GridView1"Runat="server"DataSource='<%# GetData() %>'

AutoGenerateColumns="False"

BorderWidth="1px"BackColor="White"OnRowDataBound="On_RowDataBound"CellPadding="3"BorderStyle="None"

BorderColor="#CCCCCC"Font-Names="Arial">

<FooterStyleForeColor="#000066"BackColor="White"></FooterStyle>

<PagerStyleForeColor="#000066"HorizontalAlign="Left"

BackColor="White"></PagerStyle>

<HeaderStyleForeColor="White"Font-Bold="True"

BackColor="#006699"></HeaderStyle>

<Columns>

<asp:BoundFieldHeaderText="Picutre ID"DataField="PictureID">

<ItemStyleHorizontalAlign="Center"

VerticalAlign="Middle"></ItemStyle>

</asp:BoundField>

<asp:BoundFieldHeaderText="Title"DataField="Title"></asp:BoundField>

<asp:BoundFieldHeaderText="Date Added"DataField="DateAdded"

DataFormatString="{0:d}">

<ItemStyleHorizontalAlign="Center"></ItemStyle>

</asp:BoundField>

<asp:ImageFieldDataImageUrlField="PictureURL"></asp:ImageField>

</Columns>

<SelectedRowStyleForeColor="White"Font-Bold="True"

BackColor="#669999"></SelectedRowStyle>

<RowStyleForeColor="#000066"></RowStyle>

</asp:GridView>

<asp:LinkButtonID="lnkAddAlert"runat="server"style="display:none"/>

<br/>

<br/>

<cc1:ModalPopupExtenderID="ModalPopupExtender1"runat="server"PopupControlID="Panel1"

TargetControlID="lnkAddAlert"BehaviorID="a_modal"OkControlID="cancel"BackgroundCssClass="modalBackground">

</cc1:ModalPopupExtender>

<asp:PanelID="Panel1"runat="server"Height="316px"Width="737px">

<asp:LinkButtonID="cancel"Text="close"runat="server"></asp:LinkButton>

<asp:ImageID="Image1"runat="server"Height="315px"Width="734px"/>

</asp:Panel>

</div>

</form>

</body>

</html>

And the code behind:

using System;

using System.Data;

using System.Configuration;

using System.Collections;

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;

publicpartialclassTestPages_LousTest : System.Web.UI.Page

{

protectedvoid Page_Load(object sender,EventArgs e)

{

Page.DataBind();

}

protectedDataTable GetData()

{

// This method creates a DataTable with four rows. Each row has the

// following schema:

// PictureID int

// PictureURL string

// Title string

// DateAdded datetime

DataTable dt =newDataTable();

// define the table's schema

dt.Columns.Add(newDataColumn("PictureID",typeof(int)));

dt.Columns.Add(newDataColumn("PictureURL",typeof(string)));

dt.Columns.Add(newDataColumn("Title",typeof(string)));

dt.Columns.Add(newDataColumn("DateAdded",typeof(DateTime)));

// Create the four records

DataRow dr = dt.NewRow();

dr["PictureID"] = 1;

dr["PictureURL"] = ResolveUrl("~/images/construction.png");

dr["Title"] ="Blue Hills";

dr["DateAdded"] =newDateTime(2005, 1, 15);

dt.Rows.Add(dr);

dr = dt.NewRow();

dr["PictureID"] = 2;

dr["PictureURL"] = ResolveUrl("~/images/construction.png");

dr["Title"] ="Sunset";dr["DateAdded"] =newDateTime(2005, 1, 21);

dt.Rows.Add(dr);

dr = dt.NewRow();

dr["PictureID"] = 3;

dr["PictureURL"] = ResolveUrl("~/images/construction.png");

dr["Title"] ="Water Lilies";dr["DateAdded"] =newDateTime(2005, 2, 1);

dt.Rows.Add(dr);

dr = dt.NewRow();

dr["PictureID"] = 4;

dr["PictureURL"] = ResolveUrl("../images/construction.png");

dr["Title"] ="Winter";dr["DateAdded"] =newDateTime(2005, 2, 18);

dt.Rows.Add(dr);

return dt;

}

protectedvoid On_RowDataBound(object sender,GridViewRowEventArgs e)

{

if (e.Row.RowType ==DataControlRowType.Pager)

{

return;

}

try

{

e.Row.Attributes.Add("onClick","onSelect(this);");

}

catch (Exception ex)

{

throw (newApplicationException(ex.Message));

}

}

}

Please mark as answer if it works for you and good luck.

-Louis


Oh mamma mia! I change:

<asp:GridViewID="GridView1"Runat="server"DataSource='<%# GetData() %>' ........

to

<asp:GridViewID="GridView1"Runat="server"DataSourceid="sqlsource1" ............ and all field but not worl the javascript

In original script everythin is ok, but when change for put database,don't work the error say:cells.3.children : is null or not object.

So I change in:

var sc = elem.cells[3].Rows[0].src; --> not work

var sc = elem.Rows[3].Cells[0].src; --> not work

and I delete allprotectedDataTable GetData() {........................} all delete, and

delete this line command: Page.DataBind();

But not work............Why?


Hello,

You need to do a few things if you attach a new Datasource to the grid.

Frist - find the new index of the column that holds the image path url. That column index is the new index of ele.Rows[X].Cells[columnindex].src;

Second, make sure you handle on row databound. If you post the schema of your resulting table, I can help.

Thanks,

Louis