remove the postback of an ASP button is clicked?

Posted on 2011-05-02
Last Modified: 2013-12-16
Hi to remove the postback of an ASP button is clicked?
Question by:PagodNaUtak
    LVL 13

    Accepted Solution


    Try this on your page_load event:

    button1.Attributes.Add("OnClick", "return false;")
    LVL 23

    Assisted Solution

    by:Rajkumar Gs
    Same question - Why you are trying to do so ?

    If you want to use the button click only once, you can try rick's suggestion.

    Another solution, that I have is disable the button on click
    btnButton.Enabled = False
    which I think would be decent - Otherwise end-user will think something wrong with the site and keeps on clicking on the button.

    LVL 8

    Author Comment

    Well,  I have two listbox, between the listbox there are two buttons move left and move right. When I click on the button, I do not want the entire page to reloaded. I just want the items to be updated according to the selection and button press.

    I have I explain what I need to do. Any help is greatly appreciated.

    LVL 6

    Assisted Solution

    Put the listboxes in an asp:UpdatePanel. Only this part will then reload.

    If you're new to UpdatePanels, you probably need to look around the web a bit for samples;
    LVL 83

    Assisted Solution

    I think you want to set OnClientClick

    button1.Attributes.Add("OnClientClick", "return false;")
    LVL 13

    Assisted Solution

    Then you need to use an update panel, like ingriT mentioned.
    See this link.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now