Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ImageButton event doesn't fire but Button event does

Reply
Thread Tools

ImageButton event doesn't fire but Button event does

 
 
suzanne.boyle@gmail.com
Guest
Posts: n/a
 
      06-12-2007
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.

 
Reply With Quote
 
 
 
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-13-2007
On Jun 13, 1:30 am, (E-Mail Removed) wrote:
> 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.


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);
}

 
Reply With Quote
 
 
 
 
suzanne.boyle@gmail.com
Guest
Posts: n/a
 
      06-13-2007
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.

 
Reply With Quote
 
Alexey Smirnov
Guest
Posts: n/a
 
      06-13-2007
On Jun 13, 7:33 pm, (E-Mail Removed) 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

 
Reply With Quote
 
suzanne.boyle@gmail.com
Guest
Posts: n/a
 
      06-13-2007
On 13 Jun, 21:18, Alexey Smirnov <(E-Mail Removed)> wrote:
> On Jun 13, 7:33 pm, (E-Mail Removed) 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


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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: UpdatePanel and ASP:Button - Button's Click event doesn't fire Nathan Sokalski ASP .Net 0 01-15-2009 10:00 PM
How to fire both event button click and textchanged when button is click and text is changed Amy ASP .Net 0 06-01-2006 02:33 PM
Button OnClick does not fire on first postback, but does on second Janet Collins ASP .Net 0 01-13-2006 10:08 PM
ImageButton in template column in edit mode don't fire event Wenceslao Leon ASP .Net Datagrid Control 0 09-13-2003 06:21 PM
ImageButton Event won't fire inside Template column of DataGrid KJ ASP .Net Datagrid Control 2 08-16-2003 06:19 PM



Advertisments