how to avoid post-back on button (web control) click in asp.net 2.0?

Discussion in 'ASP .Net' started by loga123, May 20, 2006.

  1. loga123

    loga123 Guest

    Hi All,

    I have a web page where I would like to do certain activities when user
    click's a button.
    I have used button web control on my page. Each time, I click this
    button....page gets posted.
    I don't want my page to do "post-back" when i click on button web
    control.
    is there any way to accomplish this?
    Can anyone help me in this regard?

    thanks
     
    loga123, May 20, 2006
    #1
    1. Advertising

  2. loga123

    Mark Rae Guest

    "loga123" <> wrote in message
    news:...

    > I have a web page where I would like to do certain activities when user
    > click's a button.
    > I have used button web control on my page. Each time, I click this
    > button....page gets posted.
    > I don't want my page to do "post-back" when i click on button web
    > control.
    > is there any way to accomplish this?
    > Can anyone help me in this regard?


    If you don't want your button to postback, that is presumably because it can
    achieve everything it needs to do client-side i.e. with JavaScript...?

    In which case, don't use an <asp:Button> control at all - simply use an HTML
    button e.g.

    <input type=button id=cmdHello value="Hello" onclick="alert('Hello');">
     
    Mark Rae, May 20, 2006
    #2
    1. Advertising

  3. loga123

    Ankit Aneja Guest

    write your code like thisin Page_load()


    if(!Page.IsPostBack)
    {

    your code

    }
    "loga123" <> wrote in message
    news:...
    > Hi All,
    >
    > I have a web page where I would like to do certain activities when user
    > click's a button.
    > I have used button web control on my page. Each time, I click this
    > button....page gets posted.
    > I don't want my page to do "post-back" when i click on button web
    > control.
    > is there any way to accomplish this?
    > Can anyone help me in this regard?
    >
    > thanks
    >
     
    Ankit Aneja, May 20, 2006
    #3
  4. You need to use javascript. Check the following
    atlas.asp.net

    Tasos
     
    Tasos Vogiatzoglou, May 20, 2006
    #4
  5. The HTML section in the toolsbox contains plain HTML controls including your
    button.
    No postbacks..


    "Mark Rae" <> schreef in bericht
    news:egl7DW$...
    > "loga123" <> wrote in message
    > news:...
    >
    >> I have a web page where I would like to do certain activities when user
    >> click's a button.
    >> I have used button web control on my page. Each time, I click this
    >> button....page gets posted.
    >> I don't want my page to do "post-back" when i click on button web
    >> control.
    >> is there any way to accomplish this?
    >> Can anyone help me in this regard?

    >
    > If you don't want your button to postback, that is presumably because it
    > can achieve everything it needs to do client-side i.e. with JavaScript...?
    >
    > In which case, don't use an <asp:Button> control at all - simply use an
    > HTML button e.g.
    >
    > <input type=button id=cmdHello value="Hello" onclick="alert('Hello');">
    >
     
    Edwin Knoppert, May 20, 2006
    #5
  6. loga123

    Darren Kopp Guest

    Are you wanting to post to a different page? If so, there is a
    property on the button where you can specify where to post to. If you
    are looking for something like javascript, you can use the HTML input,
    or put onclick attribute as the javascript you want to do, followed by
    "return false;" and i believe that will work for you.

    HTH,
    Darren Kopp
     
    Darren Kopp, May 21, 2006
    #6
  7. Re: how to avoid post-back on button (web control) click in asp.net2.0?

    That doesn't prevent a post-back. It only prevents the code to be
    executed when the post-back happens.

    Ankit Aneja wrote:
    > write your code like thisin Page_load()
    >
    >
    > if(!Page.IsPostBack)
    > {
    >
    > your code
    >
    > }
    > "loga123" <> wrote in message
    > news:...
    >> Hi All,
    >>
    >> I have a web page where I would like to do certain activities when user
    >> click's a button.
    >> I have used button web control on my page. Each time, I click this
    >> button....page gets posted.
    >> I don't want my page to do "post-back" when i click on button web
    >> control.
    >> is there any way to accomplish this?
    >> Can anyone help me in this regard?
    >>
    >> thanks
    >>

    >
    >
     
    =?ISO-8859-1?Q?G=F6ran_Andersson?=, May 21, 2006
    #7
  8. loga123

    Mark Rae Guest

    "Ankit Aneja" <> wrote in message
    news:uOGiVX$...

    > write your code like thisin Page_load()
    >
    > if(!Page.IsPostBack)
    > {
    >
    > your code
    >
    > }


    How would that stop a postback...?
     
    Mark Rae, May 21, 2006
    #8
  9. loga123

    g4j

    Joined:
    Apr 12, 2009
    Messages:
    1
    Thanks

    The return false really stop the postback. I had the simllar problem in which I wanted to use a Web Control (custom look and feel, didn't want to write CSS again) but I didn't want to use it for postback. I just added the attribute like this:

    Code:
    ''Visual Basic.Net
    btnNoPostBackButton.Attributes.Add("OnClick", "DoSomething(); return false;")
    This worked wonderfully for me. Thanks

    God Bless!
     
    g4j, Apr 12, 2009
    #9
  10. loga123

    mamikel

    Joined:
    May 15, 2009
    Messages:
    1
    Beautiful!! Thanks so much :)
     
    mamikel, May 15, 2009
    #10
    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. Kaustav Neogy

    button click does not post back

    Kaustav Neogy, Aug 13, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    549
    Kaustav Neogy
    Aug 13, 2003
  2. sylvia sil
    Replies:
    1
    Views:
    633
    Curt_C [MVP]
    Dec 29, 2004
  3. VB Programmer
    Replies:
    1
    Views:
    636
    VB Programmer
    Jan 26, 2006
  4. =?Utf-8?B?Z29yaWxsYQ==?=
    Replies:
    1
    Views:
    796
    Masudur
    May 25, 2007
  5. Replies:
    0
    Views:
    309
Loading...

Share This Page