Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / June 2007

Tip: Looking for answers? Try searching our database.

ImageButton event doesn't fire but Button event does

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
suzanne.boyle@gmail.com - 13 Jun 2007 00:30 GMT
Hi,
I'm adding an ImageButton as a child to a custom web control and
attaching an event handler to it.  When the page posts back the event
is not being fired however.  I initially assumed I had missed some
code or something however after playing about I've found that if I
change the control to a Button (or a LinkButton) the event fires.

Here is the code called in the overridden CreateChildControls method.

ImageButton btn = new ImageButton();
btn.ID = "test";
btn.AlternateText = "test";
btn.Command += new CommandEventHandler(btn_Command);

Like I say, if I change the ImageButton to a Button (and obviously
change AlternateText to Text) the event fires ok.

Can anyone shed some light on why Button works but ImageButton doesn't.
Alexey Smirnov - 13 Jun 2007 07:48 GMT
On Jun 13, 1:30 am, suzanne.bo...@gmail.com wrote:
> Hi,
> I'm adding an ImageButton as a child to a custom web control and
[quoted text clipped - 14 lines]
>
> Can anyone shed some light on why Button works but ImageButton doesn't.

This works for me

protected void Page_Load(object sender, EventArgs e)
{
ImageButton btn = new ImageButton();
btn.ID = "test";
btn.AlternateText = "test";
btn.CommandName = "test";
btn.CommandArgument = "1";
btn.Command += new CommandEventHandler(btn_Command);
form1.Controls.Add(btn);
}

void btn_Command(object sender, CommandEventArgs e)
{
Response.Write(e.CommandName + e.CommandArgument);
}
suzanne.boyle@gmail.com - 13 Jun 2007 18:33 GMT
I've found what is causing the problem.  I have some javascript on the
page that hides ImageButtons container html element when it is
clicked.  If I remove the javascript that does this it works.
Alexey Smirnov - 13 Jun 2007 21:18 GMT
On Jun 13, 7:33 pm, suzanne.bo...@gmail.com wrote:
> I've found what is causing the problem.  I have some javascript on the
> page that hides ImageButtons container html element when it is
> clicked.  If I remove the javascript that does this it works.

Great! Glad you got it working
suzanne.boyle@gmail.com - 13 Jun 2007 22:19 GMT
> On Jun 13, 7:33 pm, suzanne.bo...@gmail.com wrote:
>
[quoted text clipped - 3 lines]
>
> Great! Glad you got it working

I never actually got the ImageButton working.  It seems when I capture
the document click event or the click event of the ImageButton's
container in javascript it stops the image button postback working
correctly.  Instead I fudged a solution using a link button with an
image control inside.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.