---
title: "Disable postback on image button click asp"  
description: "Disable postback on image button click asp"  
author: "Samuel Fernandes"  
published: 2014-12-19  
updated: 2014-12-20  
canonical: https://www.mindstick.com/forum/12796/disable-postback-on-image-button-click-asp  
category: "asp.net"  
tags: ["c#"]  
reading_time: 1 minute  

---

# Disable postback on image button click asp

I have an [image button](https://www.mindstick.com/forum/1535/css-image-button) on my [asp](https://www.mindstick.com/articles/751/introduction-to-asp-dot-net-mvc) [project](https://www.mindstick.com/articles/105927/how-to-excel-at-managing-multiple-projects) that browse an image and display. I am using a [script](https://www.mindstick.com/interview/477/how-can-i-execute-a-php-script-using-command-line) for my project.

This is my [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

## ASPX:

```
<asp:Panel ID="stage" runat="server" cssClass="containment-wrapper" style="border:1px solid #000000;">         <asp:ImageButton ID="imgBrowse" runat="server" Height="375px" Width="640px" src="#" />         <input type='file' id="inpUploader" style="visibility: hidden;"/></asp:Panel>
```

**JS [source](https://www.mindstick.com/interview/840/what-happens-if-the-both-source-and-destination-are-named-same):**

```
function readURL(input) {    if (input.files && input.files[0]) {        var reader = new FileReader();         reader.onload = function (e) {            $('#imgBrowse').attr('src', e.target.result);        }         reader.readAsDataURL(input.files[0]);    }} $("#inpUploader").change(function () {    readURL(this);});
```

## CS:

```
protected void Page_Load(object sender, EventArgs e)    {        imgBrowse.Attributes.Add("onclick", "document.getElementById('inpUploader').click();");    }
```

My code is working and the image is showing after I [select](https://www.mindstick.com/forum/160534/orderby-then-select-vs-select-then-orderby-performance) the image but after a few seconds the image lost because the [page](https://www.mindstick.com/articles/13031/why-to-make-a-wikipedia-page) reloads.

## Replies

### Reply by Elena Glibart

just add return false;.

```
 protected void Page_Load(object sender, EventArgs e)    {        imgBrowse.Attributes.Add("onclick", "document.getElementById('inpUploader').click(); return false;");    }
```

### Reply by Anonymous User

```
<asp:Button runat="server"Text="Button" UseSubmitBehavior="false"
OnClientClick="alert('my client script here');my" /> <script type="text/javascript"> function my__doPostBack(eventTarget, eventArgument) {    //Just swallow the click without postback of the form}</script>
```


---

Original Source: https://www.mindstick.com/forum/12796/disable-postback-on-image-button-click-asp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
