Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 31st, 2006, 04:27 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Angel6784
Default Dynamic image button

Hello

I am having a unique problem with a webpage I am working on. I have searched high and low for an answer but was unable to find one.

I currently have a dynamically generated image button that does 2 things. When the page first loads, it is set to grab the Image thumbnail related to that particular product via ProductID, when the User clicks on the imagebutton, a popup window comes up with the large original image.

I have found a way to make that work, the problem I am running into is that everytime an image button is clicked, the whole page reloads. This can be a real problem for people who use the back button as well as a slow internet connection. :(

Here are some code of what I did: (Since I don't know how to generate a button dynamically at run-time, I have preset the buttons with the visibility at false, so when I call the functions during run time, only the buttons with an image and a URL will be visible. If anyone can help me with a better way around that, that would be awesome!) :D

 public partial class Products : System.Web.UI.Page
    {
        string strConn = ConfigurationSettings.AppSettings["CMDB"];
        int intProductID = 0;
        private void Page_Load(object sender, System.EventArgs e)
        {

            DisplayImages();

}

 protected void DisplayImages()
        {
            string strImg = String.Empty;
            string popupImg = String.Empty;
            string strImg2 = String.Empty;
            string popupImg2 = String.Empty;
            //Image imgMain = new Image();
            ImageButton imgBtn = new ImageButton();


            for (int i = 1; i < 25; i++)
            {
                strImg = "ProductThumbnail/" + intProductID + "_" + i + "Thumb.jpg";
                popupImg = "ProductImages/" + intProductID + "_" + i + ".jpg";
                strImg2 = "ProductThumbnail/" + intProductID + "_" + i + "Thumb.gif";
                popupImg2 = "ProductImages/" + intProductID + "_" + i + ".jpg";
                imgBtn = (ImageButton)Page.FindControl("ImageButton" + i);

                if (File.Exists(MapPath(strImg)))
                {
                    imgBtn.ImageUrl = strImg;
                    imgBtn.Visible = true;
                    imgBtn.Attributes.Add("onClick", "javascript:popImage('" + popupImg + "')");
                }
                else if (File.Exists(MapPath(strImg2)))
                {
                    imgBtn.ImageUrl = strImg2;
                    imgBtn.Attributes.Add("onClick", "javascript:popImage('" + popupImg2 + "')");
                    imgBtn.Visible = true;
                }
                else
                    imgBtn.Visible = false;
            }
        }

 
Old August 2nd, 2006, 10:19 AM
Authorized User
 
Join Date: Jun 2006
Posts: 85
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Creating Any Adding User Controls to a Page Dynamically.

Create a placeholder control <asp:PlaceHolder id="ph1" runat="server" />
  Dim oCtrl1 As UserControl = LoadControl("..\controls\ascx\imgbtn.ascx")
  ph1.Controls.Add(oCtrl1)

if you want to add <BR> or <P> OR Space

ph1.Controls.Add(New HtmlGenericControl("br"))
ph1.Controls.Add(New HtmlGenericControl("p"))
ph1.Controls.Add(New HtmlGenericControl("&nbsp;"))

Hope this helps.
Thanks
Ram


Rams
 
Old August 2nd, 2006, 01:25 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Angel6784
Default

Hi Rams,

I'm not quite sure what you mean by added a user control to the page dynamically. I would still need the user control to get the product images that's associated to the product the user selected. I forgot to mention that variable is passed via URL. So to get the product ID - it would be set to gather info based on the URL.
example: "www.website.com/productspage.aspx?pid=1234" so 1234 would be the productID that's used to gather the images. Images are named according to ID "1234_1.jpg" etc. Hope that clears up the problem a bit.






Similar Threads
Thread Thread Starter Forum Replies Last Post
dynamic button control SKhna ASP.NET 2.0 Basics 1 February 1st, 2008 10:36 AM
Dynamic radio Button gregd Classic ASP Basics 1 November 30th, 2006 09:42 AM
Make a image button as default submit button toshi ASP.NET 1.0 and 1.1 Basics 1 June 1st, 2006 05:25 AM
Dynamic Button Generation LouMattera BOOK: Professional C#, 2nd and 3rd Editions 2 March 4th, 2005 04:26 PM
Dynamic Image rajanikrishna Beginning PHP 1 October 8th, 2003 02:10 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.