Showing posts with label database. Show all posts
Showing posts with label database. 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

Modal popup with an image loaded from a database

I am having a bit of a problem using a modal popup which loads an image from a database. The image loads fine however the first time each image is loaded the modal popup is stuck at the top of the page with the very top of the modal extending over the top of the page. Once the image is cached and I attempt to view it again everything displays correctly. I'm not sure of the best way to fix this problem. Is there a way to have the popup only load once all of the data within the update panel has completely loaded? Here are a few code snippets so you can get an idea of what I'm doing.


I'm opening the modal when the selected item in the datagrid is changed.

protected void Grid_SelectionChanged(object source, EventArgs e)
{
dispIMG.ImageUrl ="viewImage.aspx?qIID=" + itemDG.SelectedItem.Cells[1].Text +"&sSide=Front";
 ModalPopupExtender.Show();
}
 
Any suggestions as to how I could fix this would be greatly appreciated.
 
cheers
 

any thoughts? I've tried using thread.Sleep to get the image to load before it actually opens the modal, but this doesn't seem to work. Once the image is initially loaded just simply scrolling the screen or reloading it makes everything display correctly. Banging my head on my desk for this one.

~David

Modal Poup on Page Load

Hi,

Is it possible to conditionally show modal popup on a page load instead on button click?

Before the page load, I have to check from the database if the application is available and if the application is not available then I have to show the modal popup otherwise not.

Please answer with an example.

Thanks

just write the ModalPopup.Show(); on page load.

Thanks

PS If it answers your question, please mark this post as resolved for everyone's benefit.

ModalDialog inside updatepanel

I've got a button that shows a modal dialog box. The idea is to add an object to a database, then refresh a listbox on the main page. The dialog works correctly, except with click cmdOk, the server side function is never called. I suspect it's because there's no longer an event handler registered by JS that calls the script to do the postback. I probably need to create a client side script using OnOkScript="onOK()", but I have no idea how to make the page postback to call cmdNewObject_Click without a full postback. Any ideas?

Thanks,

Rick

<asp:LinkButtonID="cmdAddObject"runat="server"Text="Add Object"></asp:LinkButton>

<cc1:ModalPopupExtenderID="ModalPopupExtender1"runat="server">

<cc1:ModalPopupPropertiesBackgroundCssClass="modalBackground"OkControlID="cmdOk"CancelControlID="cmdCancel"DropShadow="true"PopupControlID="pnlAddObject"TargetControlID="cmdAddObject"></cc1:ModalPopupProperties>

</cc1:ModalPopupExtender>

<atlas:UpdatePanelID="pnlPopup"runat="server"Mode="conditional">

<Triggers>

<atlas:ControlEventTriggerControlID="cmdOk"EventName="Click"/>

</Triggers>

<ContentTemplate>

<asp:PanelID="pnlAddObject"runat="server"CssClass="modalPopup"Style="display: none">

<div>

<divid="ObjectName">

<asp:TextBoxID="txtObjectName"runat="server"></asp:TextBox></div>

<div>

<divid="OkButton">

<asp:ButtonID="cmdOk"runat="server"OnClick="cmdNewObject_Click"Text="New Object"/></div>

<divid="CancelButton">

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

</div>

</div>

</asp:Panel>

</ContentTemplate>

</atlas:UpdatePanel>

Seethis post and maybe consider removing the OkControlID property so the Ok button can postback normally (thereby dismissing the ModalPopup). I'm thinking you may also want to get rid of the UpdatePanel here as I'm not sure it'll ultimately be necessary.

Wednesday, March 21, 2012

ModalPanel - How can I us AJAX instead of postback to update database ?

I'm new to AJAX and this suite of tools. I have a page that when a user clicks a link button my ModalPanel with various input fields appears. When the user clicks the okay button I want to make an async call instead of having the page post back. I need to be able to call one of my business objects defined in C# so what is the best way to do this?

If you can provide details or even a small example I would appreciate it.

My code behind method looks like this:

void OnClick(...)

{

Broker b = new Broker();

b.name = NameTextBox.Text;

b.account = AccountTextBox.Text;

b.Save();


}

Why not just wrap the modalpopup in an updatepanel and let the page postback? It is easier then to have access to the server controls from the form and have full interaction with the other page elements during the postback in case you want to update other stuff on the page.

What benefits are you looking for by not posting back?

Jason

modalpopup

hii need to use a modalpopup to add an item to my dropdownlist.my dropdownliste extract the itmes from an oracle database.

the client click on a botton to add the new item in the database and i want that the ddl refreshe.

can u help me plez.

1<asp:Panel runat="server" id="pnl_add">2 <asp:TextBox runat="server" id="txt_name" />3 <asp:RequiredFieldValidator runat="server" id="rfv_name"4 ControlToValidate="txt_name"5 ToolTip="Please enter a name"6 ErrorMessage=" *" />7 <asp:Button runat="server" id="btn_ok"8 Text="Ok" />9 <asp:Button runat="server" id="btn_cancel"10 Text="Cancel" />11</asp:Panel>12<ajaxToolkit:ModalPopupExtender runat="server" id="mpe_add"13 TargetControl="btn_add"14 PopupControlID="pnl_add"15 CancelControlID="btn_Cancel" />1617<asp:UpdatePanel runat="server" id="up_items"18 RenderMode="block"19 UpdateMode="conditional">20 <Triggers>21 <asp:AsyncPostBackTrigger22 ControlID="btn_Ok"23 EventName="Click" />24 </Triggers>25 <ContentTemplate>26 <asp:DropDownList runat="server" id="ddl_items" />27 </ContentTemplate>28</asp:UpdatePanel>
1Protected Sub btn_Ok_Click(sender asObject, e as EventArgs) handles btn_Ok.Click2'insert into database34 up_items.Update()5End Sub