<a href> around an <asp:imagebutton> not working - need some help

G

Guest

I have an HTML table with several fields like this:

<A href="Savings.aspx?category=Food"><asp:imagebutton id="imgFood"
ImageUrl="images\buttons\btn-food-i.gif" runat="server"></asp:imagebutton></A>

When the user sees these buttons, they will currently be on the
savings.aspx?category=whatever page, and when they click another button to
look at other categories, all the links I have around these buttons direct to
their various categories.

However, when I press these buttons, nothing happens.

Did I forget to do something here?

thanks for the help
 
G

Guest

I also tried removing the <a href> tags around the ImageButtons and creating
Click events for the buttons with
Response.Redirect("savings.aspx?category=whatever");
and placed a breakpoint on these statements in my Click code and they don't
event get executed.

I must be missiong something really small here :p

Thanks again
 
P

Peter Rilling

That is probable because the ImageButton is rendered as an <input> element
in the HTML.

Why do you want to wrap an ImageButton in an anchor? Suppose what you
wanted to do works, when the postback happens, how is the hyperlink suppose
to react since the past has already navigated. After all, the browser
cannot navigate to two pages at the same time.
 
L

Lau Lei Cheong

Yes. This is the right way to do what you want.

If your button do not receive event, make sure you see something like this
in "Generated by form designer" part of code:

imgFood.Click += new ImageClickEventHandler(imgFoodClick);

The form designer should have added this to your code, but sometime for
unknown reason they're removed, so you should check it first.
 
E

Eliyahu Goldin

What server-side functionality do you expect from the imagebutton? Can you
do just

<A href="Savings.aspx?category=Food"><:img
src="images\buttons\btn-food-i.gif"></A>


Eliyahu
 
G

Guest

I need to change the images depending on the category so that the "actrive"
category has a different image differentiating it from the others; that is
why I'm using a server side control
 
G

Guest

<td><asp:imagebutton id="imgHair" ImageUrl="images\buttons\btn-hair-i.gif"
runat="server"></asp:imagebutton></td>I do have the Event handlers... here is
my current html:


and my event handler:
this.imgHair.Click += new
System.Web.UI.ImageClickEventHandler(this.imgHair_Click);

and my function:
private void imgHair_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
Response.Redirect("savings.aspx?category=Hair");
}

I'm baffled.
 
G

Guest

That is what i originally did, and I was getting the same result - nothing.
It looked like it was posting back but it didn't go through the Page_Load
again. I set a break point there and nothing.
 
E

Eliyahu Goldin

Did not you first ask on an imagebutton inside a hyperlink? Why do you want
to redirect in the imagebutton event if the hyperlink does it for you? Make
your mind and navigate with only one control : either the button or the
link.

Eliyahu

tperri said:
<td><asp:imagebutton id="imgHair" ImageUrl="images\buttons\btn-hair-i.gif"
runat="server"></asp:imagebutton></td>I do have the Event handlers... here is
my current html:


and my event handler:
this.imgHair.Click += new
System.Web.UI.ImageClickEventHandler(this.imgHair_Click);

and my function:
private void imgHair_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
 
E

Eliyahu Goldin

In your original post you had an imagebutton inside a hyperlink. I am
suggesting having an image, not imagebutton. What page do you expect
Page_Load to happen? If you user the hyperlink for navigating, there won't
be any postback to the original form. Browser will navigate straight to the
new url.

Eliyahu
 
G

Guest

Ok, forget all the code I posted to you.

I replaced everything with an Image Button .... in the Click event of that
button I have a Response.Redirect("savings.aspx?category=Whatever"); and that
doesn't work....

have any idea about that?
 
L

Lau Lei Cheong

Then, give your server-side form an id and try to type the following line in
the address bar of your browser after your page is opened.

javascript:window.alert(document.getElementById('imgHair').form.id)

If the browser popups undefined/null/<blank> but not your form's id, you
should consider checking to see if all html tags(especially <form> and
<table>)are properly closed and not overlapped. In this case the imagebutton
is not attached to the postbackable form so not postback event can be fired.
 
G

Guest

I guess it's not a good sign if I do this.. and nothing happens.. and in the
lower bar of IE I get the yellow exclamation point that says error on page :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top