Solved

create image  button dynamically

Posted on 2006-07-03
6
831 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
Comment Utility
Is "imgButtonClick" a javascript function ?
0
 
LVL 9

Expert Comment

by:zaghaghi
Comment Utility
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
Comment Utility
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Accepted Solution

by:
zaghaghi earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now