Solved

create image  button dynamically

Posted on 2006-07-03
6
835 Views
Last Modified: 2008-01-09
I am trying to create image control  button's dynamically. I am able to get the image  button's to display, but the on clientClientClick function I wrote is not capturing the event when I click on the button. Am I missing something? Please see code below. Thanks.


            Table table = (Table)this.FindControl("_table");
            TableRow tr = new TableRow();
            TableCell tdButton = new TableCell();

             ImageButton button = new ImageButton();
             button.ID = "imgButton_" + i;
             button.OnClientClick = "imgButtonClick";
             button.ImageUrl = "images/folder.gif";
             button.Visible = true;

             tdButton.Controls.Add(button);

             tr.Cells.Add(tdButton);
               
             table.Rows.Add(tr);

0
Comment
Question by:LeeHenry
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
6 Comments
 
LVL 52

Expert Comment

by:Carl Tawn
ID: 17033733
Is "imgButtonClick" a javascript function ?
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17033834
when you use OnClientClick porperty of an image button, it's means that you have a script function named imgButtonClick in your aspx page and use that function for client click,

but if you want to handle image click event on the server you must write code like this:

button.OnClick += new EventHandler(imgButtonClick);
0
 
LVL 6

Author Comment

by:LeeHenry
ID: 17033859
zaghaghi,

I tried it out, but i'm getting the below error:

Error      2      'System.Web.UI.WebControls.ImageButton.OnClick(System.Web.UI.ImageClickEventArgs)' is inaccessible due to its protection level      
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Accepted Solution

by:
zaghaghi earned 500 total points
ID: 17033907
i use this in asp.net 2

        ImageButton button = new ImageButton();
        button.Click += new ImageClickEventHandler(button_Click);


and implement the button_click like this
    protected void Button1_Click(object sender, EventArgs e)
    {
        TextBox1.Text = DateTime.Now.ToString();
    }
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17033908
Ooooooops error in paste

and implement the button_click like this
    void button_Click(object sender, ImageClickEventArgs e)
    {
       
    }
0
 
LVL 9

Expert Comment

by:zaghaghi
ID: 17033923
also you can do this:

first declare the image button
ImageButton button = new ImageButton();

secon use visual studio features to create the event handler:

type

button.Click +=

then press TAB to create this:

button.Click += ImageClickEventHandler(button_Click);

and then press TAB again to create the button_click method

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Just a quick little trick I learned recently.  Now that I'm using jQuery with abandon in my asp.net applications, I have grown tired of the following syntax:      (CODE) I suppose it just offends my sense of decency to put inline VBScript on a…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question