Solved

create image  button dynamically

Posted on 2006-07-03
6
834 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
  • 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

825 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