Click here to Skip to main content
15,910,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Every thing is going fine but here i want when ASP form loaded with controls and control filled with data from database.
Then i want to click on image for re sizing it.How can i do it.Is it possible? if yes, Please someone help me.
C#
<pre lang="C#">//Fill page with dynamic controls showing products in database
    private void GenerateControls()
    {
        //Get all coffeeObjects from database
        ArrayList coffeeList = Connectionclass.GetCoffeeByType(&quot;%&quot;);

        foreach (Coffee coffee in coffeeList)
        {
            //Create Controls
            Panel coffeePanel = new Panel();
            
            Image image = new Image { ImageUrl = coffee.Image };            
            Literal literal = new Literal { Text = &quot;&lt;br /&gt;&quot; };
            Literal literal2 = new Literal { Text = &quot;&lt;br /&gt;&quot; };
            Label lblName = new Label { Text = coffee.Name };
            
            
                
            Label lblPrice = new Label
            {
                Text = String.Format(&quot;{0:0.00}&quot;, coffee.Price + &quot;&lt;br /&gt;&quot;),
                CssClass = &quot;ProductsPrice&quot;
            };
            TextBox textBox = new TextBox
            {
                ID = coffee.Id.ToString(),
                CssClass = &quot;ProductsTextBox&quot;,
                Width = 60,
                Text = &quot;0&quot;
            };

            //Add validation so only numbers can be entered into the textfields
            RegularExpressionValidator regex = new RegularExpressionValidator
            {
                ValidationExpression = &quot;^[0-9]*&quot;,
                ControlToValidate = textBox.ID,
                ErrorMessage = &quot;Please enter a number.&quot;
            };

            //Add controls to Panels
            coffeePanel.Controls.Add(image);
            coffeePanel.Controls.Add(literal);
            coffeePanel.Controls.Add(lblName);
            coffeePanel.Controls.Add(literal2);
            coffeePanel.Controls.Add(lblPrice);
            coffeePanel.Controls.Add(textBox);
            coffeePanel.Controls.Add(regex);

            pnlProducts.Controls.Add(coffeePanel);
        }
    }</pre>


What I have tried:

How can i create click event here for re sizing image on dynamically created Image control? with c# asp.net
Posted
Updated 10-Apr-16 1:10am
v4
Comments
Arvind Zamakia 9-Apr-16 23:02pm    
You can every images are re size so used http handlers to resize image dll used.
Kornfeld Eliyahu Peter 10-Apr-16 8:00am    
Image control in ASP.NET has no click event, so you will need some button next to it, to handle the click...

1 solution

Something like this in WinForms (saw too late that you mentioned ASP, please tag question as ASP):
C#
private void GenerateControls()
{
    Button button = new Button();
    button.BackgroundImage = Image.FromFile("coffee.png");
    button.BackgroundImageLayout = System.Windows.Forms.ImageLayout.None;
    coffeePanel.Controls.Add(button);
    button.Click += new System.EventHandler(this.button1_Click);
}

private void button1_Click(object sender, EventArgs e)
{
    MessageBox.Show("Clicked !");
}

If you don't want to see the button borders, set the properties as follows:
button.FlatStyle = FlatStyle.Flat;
button.FlatAppearance.BorderSize = 0;
 
Share this answer
 
v3
Comments
Member 10267889 10-Apr-16 6:21am    
HI,I can't solve my problem like that please give me exact code if it possible
thanks.
RickZeeland 10-Apr-16 6:43am    
Sorry, I'm not good at ASP, maybe someone else can answer this ?
Member 10267889 10-Apr-16 6:45am    
ok,thanks

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