Solved

create image  button dynamically

Posted on 2006-07-03
6
836 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
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!

 
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

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…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

688 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