Stop Postback in image button

N

nachoenjuto

Hi people

Does anyone know how whether there is any property, way or trick to
stop the postback of a image button??

I need the image button to change its behavour after the first click.
The image button expands an area that contains more information, The
first click would be a postback with a database query to get some extra
info and put it in expandable area.
The second click and consecutives would just collapse and expand this
expandable area

Does anyone know if this is posible with just jusing one image button??

Thank you!
 
A

Alessandro Zifiglio

hi, sure you can. Try the following code i used to make a simple example.

Regards,
Alessandro Zifiglio
http://www.AsyncUI.net

<%@ Page Language="C#" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">

protected void ImageButton1_Command(object sender, CommandEventArgs e)
{
/*do something here, it will fire only the first time the image
button is clicked.
the next time onwards, the following jscode will be injected
which cancels the submit and
instead makes it expand and collapse the the li node with id
'collapsible1'
*/
collapsible1.InnerText = "some stuff for the body, coming from your
database";
ImageButton1.Attributes.Add("onclick",
"document.getElementById('collapsible1').style.visibility =
((document.getElementById('collapsible1').style.visibility == 'visible') ?
'hidden' : 'visible'); return false");

}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<ul style="list-style-type:none">
<li>head <asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/url/to/your/image" OnCommand="ImageButton1_Command" /></li>
<li id="collapsible1" runat="server"
style="visibility:visible"></li>
</ul>

</div>
</form>
</body>
</html>
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top