473,404 Members | 2,174 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

How to: Get "name" property of button from click event

Using .Net Compact Framework, I have an ImageButton control (derived from the
Button control) this is wired to a click event. The click event's receives
the standard arguments (sender, e). How is it possible from within the click
event function to get the "name" property of the control? For example:
ImageButton ImageButton1 = new ImageButton();
ImageButton1.Click += new System.EventHandler(ImageButton1_Click);
.... code
private void ImageButton1_Click(object sender, System.EventArgs e)
{
string name = ((ImageButton)sender).name???
}

Thanks,

Nov 16 '05 #1
7 14396
Doesn't your code work?

private void ImageButton1_Click(object sender, System.EventArgs e)
{
string name = ((ImageButton)sender).Name;
}

Nov 16 '05 #2
No. In the VS .NET 2003, i get the error: 'System.ImageButton' does not
contain a definition for 'Name'. I've tried this w/ more conventional
controls, like the Button control, and i get: 'System.Windows.Forms.Button'
does not contain a definition for 'Name'

??

"sadhu" wrote:
Doesn't your code work?

private void ImageButton1_Click(object sender, System.EventArgs e)
{
string name = ((ImageButton)sender).Name;
}

Nov 16 '05 #3
It doesn't look as if the ImageButton has a Name property. Have you
tried the ID property? Will that work for you?

Just a thought.

Nov 16 '05 #4
There is no "ID" property either. This is quite strange as in "design mode" i
can set such properties...

"Chris Dunaway" wrote:
It doesn't look as if the ImageButton has a Name property. Have you
tried the ID property? Will that work for you?

Just a thought.

Nov 16 '05 #5
Are you sure you are using Name (typed in the correct case)? Remember,
C# is case sensitive.

The Button class does have a Name property, in fact, if you read
through the InitializeComponent() method in your form class, you'll see
that it actually sets the Name to whatever you typed in the UI. The
Name property is defined in the Control base class, and so should be
available to all controls.

Regards
Senthil

Nov 16 '05 #6
Yes, the "Name" value is properly typed. I'm not an expert, but my
ImageButton class (which i downloaded from some spot on the Web) is not
derived from the Button class, but instead from the "Control" class. At
least, i think this is so. The code reads:

public class ImageButton : Control
{
// ... code
}

In the Compact Framework, there is no "ImageButton" as there is in the
complete .Net Framework. And, i believe that the actual image that appears on
the screen is derived from the system.drawing.image class.

Does this make it easier for anyone to answer my question? Thanks.

"sadhu" wrote:
Are you sure you are using Name (typed in the correct case)? Remember,
C# is case sensitive.

The Button class does have a Name property, in fact, if you read
through the InitializeComponent() method in your form class, you'll see
that it actually sets the Name to whatever you typed in the UI. The
Name property is defined in the Control base class, and so should be
available to all controls.

Regards
Senthil

Nov 16 '05 #7
You have the code? Then why don't you add a Name property to it?

Nov 16 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: ST | last post by:
Hi, I'm new to vb.net programming, and I keep getting this error: Name 'GetQuery' is not declared. I can't figure out why?? It seems like I have the right references/namespaces. This is my code...
6
by: Java script Dude | last post by:
We just discovered another IE bug. When an html form contains an element with a name of `name` IE's internal index screws up the .name property of the containing form to point to the bad element...
4
by: Marc Elser | last post by:
Hi Everybody, Can someone please tell me how to access the form name if there's a form field named "name", for example: <form name="myform"> <input type="text" name="name" value="Marc">...
3
by: Pavils Jurjans | last post by:
Hello, I have bumped upon this problem: I do some client-side form processing with JavaScript, and for this I loop over all the forms in the document. In order to identify them, I read their...
13
by: Mark Kamoski | last post by:
Hi Everyone-- How can one to make a "select directory name" dialog? It would be great if one could use the FileOpenDialog but it does not seem to be straight-forward. Anyway, if you have...
5
by: engsolnorm | last post by:
I'm playing with a sudoku GUI...just to learn more about python. I've made 81 'cells'...actually small canvases Part of my scheme to write the cells (all 81 of them in the gui) to a file (using...
4
by: ajschuster | last post by:
I cannot get my Javascript to work in Firefox. I am just trying to access the .name property of a DIV tag but it keeps coming back as "undefined". The same code works in IE and it works in...
6
by: Dick Watson | last post by:
I had a page that works when setup like this: === <form name="frmCalc" action=""> <script type="text/javascript"> function btnCalc_onclick(abc) { return "got here with " + abc; }
0
by: | last post by:
I'd like to change the "Product name" property on a (Win32) DLL - AFTER it's been built. Basically, I have a post-processing tool that modifies the DLL in a way that can't easily be detected. I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.