Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 31st, 2006, 04:27 PM
Registered User
 
Join Date: Jul 2006
Location: , California, USA.
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;
            }
        }

Reply With Quote
  #2 (permalink)  
Old August 2nd, 2006, 10:19 AM
Authorized User
 
Join Date: Jun 2006
Location: Chelmsford, MA, USA.
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
Reply With Quote
  #3 (permalink)  
Old August 2nd, 2006, 01:25 PM
Registered User
 
Join Date: Jul 2006
Location: , California, USA.
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.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:23 PM.


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