Stop Postback in image button

Discussion in 'ASP .Net Web Controls' started by nachoenjuto@gmail.com, Jul 26, 2006.

  1. Guest

    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!
     
    , Jul 26, 2006
    #1
    1. Advertising

  2. 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>
    <> ha scritto nel messaggio
    news:...
    > 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!
    >
     
    Alessandro Zifiglio, Jul 26, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt Theule

    Stop Debugging doesn't stop in ASP.NET

    Matt Theule, Jul 23, 2003, in forum: ASP .Net
    Replies:
    7
    Views:
    775
    Matt Theule
    Jul 24, 2003
  2. Son KwonNam
    Replies:
    11
    Views:
    2,647
    mr_organic
    Apr 9, 2004
  3. gerry
    Replies:
    3
    Views:
    480
    Walter Wang [MSFT]
    Nov 23, 2007
  4. Matthew Wells

    Stop postback/refresh using a button...

    Matthew Wells, Mar 1, 2008, in forum: ASP .Net
    Replies:
    3
    Views:
    3,443
    Ralph
    Sep 16, 2009
  5. Wael_Bakr

    stop postback in postback events for server controls ??

    Wael_Bakr, Nov 30, 2005, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    522
    Wael_Bakr
    Nov 30, 2005
Loading...

Share This Page