Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ImageButton OnClientClick Events Not Firing on Client

Reply
Thread Tools

ImageButton OnClientClick Events Not Firing on Client

 
 
=?Utf-8?B?RWFnbGVSZWRASGlnaEZseWluZ0JpcmRzLmNvbQ==?=
Guest
Posts: n/a
 
      11-14-2007
I am having trouble getting client-side events to fire on ImageButtons.
Instead I am seeing postbacks. The client-side handlers end with "return
false;" but they are never called.

<asp:ImageButton id="myButton" runat="server"
OnClientClick="myButtonClick();" src=... ></asp:ImageButton>

In the javascript:

function myButtonClick()
{
alert("myButton clicked");
return false;
}

What can the problem be?

Thank you!
Eagle
 
Reply With Quote
 
 
 
 
=?Utf-8?B?Sm9uIEdvbnphbGVz?=
Guest
Posts: n/a
 
      11-14-2007
Try to add "return" to tell the button to depend on the return value of the
script that is being called.

instead of: OnClientClick="myButtonClick();"
use this: OnClientClick="return myButtonClick();"

Cheers!

"(E-Mail Removed)" wrote:

> I am having trouble getting client-side events to fire on ImageButtons.
> Instead I am seeing postbacks. The client-side handlers end with "return
> false;" but they are never called.
>
> <asp:ImageButton id="myButton" runat="server"
> OnClientClick="myButtonClick();" src=... ></asp:ImageButton>
>
> In the javascript:
>
> function myButtonClick()
> {
> alert("myButton clicked");
> return false;
> }
>
> What can the problem be?
>
> Thank you!
> Eagle

 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      11-14-2007
View html source for the rendered page. What is there for myButton?

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"(E-Mail Removed)"
<(E-Mail Removed). com> wrote in message
news:(E-Mail Removed)...
>I am having trouble getting client-side events to fire on ImageButtons.
> Instead I am seeing postbacks. The client-side handlers end with "return
> false;" but they are never called.
>
> <asp:ImageButton id="myButton" runat="server"
> OnClientClick="myButtonClick();" src=... ></asp:ImageButton>
>
> In the javascript:
>
> function myButtonClick()
> {
> alert("myButton clicked");
> return false;
> }
>
> What can the problem be?
>
> Thank you!
> Eagle



 
Reply With Quote
 
=?Utf-8?B?Sm9uIEdvbnphbGVz?=
Guest
Posts: n/a
 
      11-15-2007
What?

"Eliyahu Goldin" wrote:

> View html source for the rendered page. What is there for myButton?
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
> http://usableasp.net
>
>
> "(E-Mail Removed)"
> <(E-Mail Removed). com> wrote in message
> news:(E-Mail Removed)...
> >I am having trouble getting client-side events to fire on ImageButtons.
> > Instead I am seeing postbacks. The client-side handlers end with "return
> > false;" but they are never called.
> >
> > <asp:ImageButton id="myButton" runat="server"
> > OnClientClick="myButtonClick();" src=... ></asp:ImageButton>
> >
> > In the javascript:
> >
> > function myButtonClick()
> > {
> > alert("myButton clicked");
> > return false;
> > }
> >
> > What can the problem be?
> >
> > Thank you!
> > Eagle

>
>
>

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      11-15-2007
When viewing the page in the browser, rightclick the browser window and
choose "View Source" (that is in IE, other browsers may have different name
for the same function). You will see the html for the page you are viewing.
Then find in the html a control with id containing "myButton". You will see
what html code asp.net produced for the button. It may help you in
understanding the problem.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Jon Gonzales" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> What?
>
> "Eliyahu Goldin" wrote:
>
>> View html source for the rendered page. What is there for myButton?
>>
>> --
>> Eliyahu Goldin,
>> Software Developer
>> Microsoft MVP [ASP.NET]
>> http://msmvps.com/blogs/egoldin
>> http://usableasp.net
>>
>>
>> "(E-Mail Removed)"
>> <(E-Mail Removed). com> wrote in message
>> news:(E-Mail Removed)...
>> >I am having trouble getting client-side events to fire on ImageButtons.
>> > Instead I am seeing postbacks. The client-side handlers end with
>> > "return
>> > false;" but they are never called.
>> >
>> > <asp:ImageButton id="myButton" runat="server"
>> > OnClientClick="myButtonClick();" src=... ></asp:ImageButton>
>> >
>> > In the javascript:
>> >
>> > function myButtonClick()
>> > {
>> > alert("myButton clicked");
>> > return false;
>> > }
>> >
>> > What can the problem be?
>> >
>> > Thank you!
>> > Eagle

>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?Sm9uIEdvbnphbGVz?=
Guest
Posts: n/a
 
      11-15-2007
Definitely not, it doesn't make sense viewing the rendered script for the
button, just to the return thing, it will definitely fix the problem.

Correct me if I'm wrong.

Cheers!

"Eliyahu Goldin" wrote:

> When viewing the page in the browser, rightclick the browser window and
> choose "View Source" (that is in IE, other browsers may have different name
> for the same function). You will see the html for the page you are viewing.
> Then find in the html a control with id containing "myButton". You will see
> what html code asp.net produced for the button. It may help you in
> understanding the problem.
>
> --
> Eliyahu Goldin,
> Software Developer
> Microsoft MVP [ASP.NET]
> http://msmvps.com/blogs/egoldin
> http://usableasp.net
>
>
> "Jon Gonzales" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > What?
> >
> > "Eliyahu Goldin" wrote:
> >
> >> View html source for the rendered page. What is there for myButton?
> >>
> >> --
> >> Eliyahu Goldin,
> >> Software Developer
> >> Microsoft MVP [ASP.NET]
> >> http://msmvps.com/blogs/egoldin
> >> http://usableasp.net
> >>
> >>
> >> "(E-Mail Removed)"
> >> <(E-Mail Removed). com> wrote in message
> >> news:(E-Mail Removed)...
> >> >I am having trouble getting client-side events to fire on ImageButtons.
> >> > Instead I am seeing postbacks. The client-side handlers end with
> >> > "return
> >> > false;" but they are never called.
> >> >
> >> > <asp:ImageButton id="myButton" runat="server"
> >> > OnClientClick="myButtonClick();" src=... ></asp:ImageButton>
> >> >
> >> > In the javascript:
> >> >
> >> > function myButtonClick()
> >> > {
> >> > alert("myButton clicked");
> >> > return false;
> >> > }
> >> >
> >> > What can the problem be?
> >> >
> >> > Thank you!
> >> > Eagle
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      11-15-2007
You are right, adding "return..." is necessary. But I am referring to the
OP's statement:

>> >> > ... The client-side handlers end with
>> >> > "return
>> >> > false;" but they are never called.


If the event handler indeed is never called, viewing html will help.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


"Jon Gonzales" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Definitely not, it doesn't make sense viewing the rendered script for the
> button, just to the return thing, it will definitely fix the problem.
>
> Correct me if I'm wrong.
>
> Cheers!
>
> "Eliyahu Goldin" wrote:
>
>> When viewing the page in the browser, rightclick the browser window and
>> choose "View Source" (that is in IE, other browsers may have different
>> name
>> for the same function). You will see the html for the page you are
>> viewing.
>> Then find in the html a control with id containing "myButton". You will
>> see
>> what html code asp.net produced for the button. It may help you in
>> understanding the problem.
>>
>> --
>> Eliyahu Goldin,
>> Software Developer
>> Microsoft MVP [ASP.NET]
>> http://msmvps.com/blogs/egoldin
>> http://usableasp.net
>>
>>
>> "Jon Gonzales" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > What?
>> >
>> > "Eliyahu Goldin" wrote:
>> >
>> >> View html source for the rendered page. What is there for myButton?
>> >>
>> >> --
>> >> Eliyahu Goldin,
>> >> Software Developer
>> >> Microsoft MVP [ASP.NET]
>> >> http://msmvps.com/blogs/egoldin
>> >> http://usableasp.net
>> >>
>> >>
>> >> "(E-Mail Removed)"
>> >> <(E-Mail Removed). com> wrote in
>> >> message
>> >> news:(E-Mail Removed)...
>> >> >I am having trouble getting client-side events to fire on
>> >> >ImageButtons.
>> >> > Instead I am seeing postbacks. The client-side handlers end with
>> >> > "return
>> >> > false;" but they are never called.
>> >> >
>> >> > <asp:ImageButton id="myButton" runat="server"
>> >> > OnClientClick="myButtonClick();" src=... ></asp:ImageButton>
>> >> >
>> >> > In the javascript:
>> >> >
>> >> > function myButtonClick()
>> >> > {
>> >> > alert("myButton clicked");
>> >> > return false;
>> >> > }
>> >> >
>> >> > What can the problem be?
>> >> >
>> >> > Thank you!
>> >> > Eagle
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
Aaron
Guest
Posts: n/a
 
      11-30-2007
I'm having the exact same issue as OP's. I have a master page with an
"authentication" control at the top that contains a username and
password text inputs. There is a "login" ImageButton. The login image
button has postback event (click event) and OnClientClick function
call that simply "return false;". If I make
OnClientClick="alert('hello'); return false;", it does what I expect.
However, if I do OnClientClick="return myFunction();" where
myFunction() { return false; }, I get a postback. I'm curious if the
original post developer is also using master pages.

-ak
 
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
asp:ImageButton and onClientClick and page refresh rum23 ASP .Net Web Controls 1 01-24-2009 01:25 PM
Problem with ImageButton.OnClientClick when DataBinding Nathan Sokalski ASP .Net 3 08-01-2007 05:44 PM
Problem with ImageButton.OnClientClick when DataBinding Nathan Sokalski ASP .Net Web Controls 3 08-01-2007 05:44 PM
Onclientclick firing twice? Steve ASP .Net 4 02-07-2006 04:52 PM
ImageButton events stopped firing on client? Darren Clark ASP .Net 2 06-25-2004 07:33 AM



Advertisments