Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have an image on my page.

I want this image to reload when I click on button "Refresh" because when I click on button "Refresh", the content of the picture will change.

Help me please.

Thanks in advance!
Posted
Updated 9-Feb-11 22:17pm
v5
Comments
Sunasara Imdadhusen 9-Feb-11 6:29am    
Do you have list of images? that will be stored in Array?
ngthtra 10-Feb-11 2:48am    
no I have only a image.
Dalek Dave 10-Feb-11 4:17am    
Minor Edite for Readability.

1. So the refresh button does exactly what?
2. Is a new page requested or is an AJAX call being made to the server?
3. How is the image delivered (from webserver file (.jpg,.png, etc.) or via an aspx/asmx page
4. What do you mean by the content of the picture changed?
Does it mean the picture will be generated or do you want to display another already existing image.

Please elaborate on your question because as it stands right know your chances of getting an answer are more than slim.

Cheers!
 
Share this answer
 
Comments
Sunasara Imdadhusen 9-Feb-11 6:52am    
Manfred, you are right!
Try the following:
xyz.aspx

XML
<asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="Conditional">
                        <ContentTemplate>
                            <asp:Image ID="imgContainer" runat="server" Height="51px" Width="212px" />
                        </ContentTemplate>
                        <Triggers>
                            <asp:AsyncPostBackTrigger ControlID="imbReLoad" />
                        </Triggers>
                    </asp:UpdatePanel>
                    <asp:ImageButton ID="imbReLoad" runat="server" Height="31px" ImageUrl="image url here"
                        OnClick="imbReLoad_Click" Width="33px" />


xyz.cs

C#
protected void imbReLoad_Click(object sender, ImageClickEventArgs e)
   {
       //call function to refresh image
       
   }
 
Share this answer
 
Comments
ngthtra 10-Feb-11 2:57am    
thanks your way but it is not resolve my problem
I hope that I will receive your help, thanks.
my code as below:
XML
<asp:Image ID="imgCapcha" runat="server" Height="51px" Width="212px" />
               <asp:UpdatePanel ID="UpdatePanel1" runat="server" >
               <ContentTemplate >
                &nbsp;&nbsp;&nbsp;
               <asp:ImageButton ID="imbReLoad" runat="server" Height="31px"
                   ImageUrl="~/hinhtrangtri/refresh.png" OnClick="imbReLoad_Click"
                   Width="33px" />
               </ContentTemplate>
             </asp:UpdatePanel>


and code at class codebehind:

// code create image capchar
    public void TaoAnhCapcha()
    {
        string[] Fonts = { "Arial Black", "Arial" };
        byte bLenght = 6;
        string chars = "12345678ABCDEFGHIJKLMNOPQRSTUVWXYZabdeqptmnghr"; ;
        Bitmap bmp = new Bitmap(125, 30);
        Graphics gr = Graphics.FromImage(bmp);
        // chọn kiểu hiển thị của bipmap kiểu gợn sóng
        // choose type of bipmap
        HatchBrush brush = new HatchBrush(HatchStyle.Wave, Color.White, Color.Wheat);
        gr.FillRegion(brush, gr.Clip);
        //Lưu chuỗi capcha trong quá trình tạo
        StringBuilder strCapCha = new StringBuilder();
        Random Rand = new Random();
        int x = 1;
        for (int i = 0; i < bLenght; i++)
        {
            // Lấy ký tự ngẫu nhiên từ mảng chars
            // get ramdom char
            string schar = chars[Rand.Next(chars.Length)].ToString();
            strCapCha.Append(schar);
            // Tạo font với font ngẫu nhiên chọn từ Fonts
            //create font with ramdom font
            Font font = new Font(Fonts[Rand.Next(Fonts.Length)], 12, FontStyle.Bold | FontStyle.Italic);
            //Lầy kích thước của ký tự
            //get the size of char
            SizeF size = gr.MeasureString(schar, font);
            // Vẽ Ký tự ra ảnh theo thứ tự tăng dần với tọa độ X tăng dần theo i và Y ngẫu nhiên
            //draw char to image
            gr.DrawString(schar, font, Brushes.Blue, x * 2, Rand.Next(2, 10));
            font.Dispose();
            x += 10;
        }
        // Lưu captcha vào session 
        //save capchar to session
        Session["captcha"] = strCapCha.ToString();
        //// Lưu ảnh vào thư mục Capcha với tên ảnh dựa theo IP 
        //save image into folder "hinhtrangtri"
        string path = "hinhtrangtri/" + Request.UserHostAddress + ".gif";
        bmp.Save(Server.MapPath("") + "/" + path, System.Drawing.Imaging.ImageFormat.Gif);
                    
        imgCapcha.ImageUrl = path; // it is not refresh the content of image capchar
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            //call function create image capchar
            TaoAnhCapcha();     
        }
    }
    // when user click on this image button, it create new a capchar (the same refresh this image capchar)
    protected void imbReLoad_Click(object sender, ImageClickEventArgs e)
    {
        //CreateCaptcha();
        //call function create image capchar
        TaoAnhCapcha();
    }
 
Share this answer
 
Comments
Dalek Dave 10-Feb-11 4:18am    
Very comprehensive, have a 5
ngthtra 11-Feb-11 6:41am    
my code can not reload the content of image capchar when clicked on button imbReLoad, althought the content of image capchar is changed when I clicked

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900