Solved

Is it possible to disable an ImageButton when processing?

Posted on 2013-12-19
7
195 Views
Last Modified: 2014-08-14
Is it possible to disable an ImageButton when processing?

I found a way to disable a Button when processing doing this:

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then

           Dim strProcessScript As String = "this.value='Processing...';this.disabled=true;"
           btnProcess.Attributes.Add("onclick", (strProcessScript + ClientScript.GetPostBackEventReference(btnProcess, "").ToString))

        End If
    End Sub

Open in new window

But I can't do the same for an ImageButton
0
Comment
Question by:miyahira
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 22

Expert Comment

by:Mrunal
ID: 39730964
Try same thing for image button, only change the following...


imagebtnidhere.Attributes.Add("onclick", (ClientScript.GetPostBackEventReference(btnProcess, "").ToString) + ";return false;")


This will result in even you click on image button, nothing will happen.

But remember to remove that "return false;" when processing is done.
0
 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 39731637
hi.. you can disable button like this
Write this code in button clicked event. It is for disable button for some time.

Javascript :
<script type="text/javascript">
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
function BeginRequestHandler(sender, args) {
document.getElementById('<%= lblMessage.ClientID %>').innerText = "Please Wait...";
document.getElementById('<%= btnSubmit.ClientID %>').innerText = "Please Wait";
args.get_postBackElement().disabled = true;
}
</script>

Code behind :

protected void btnSubmit_Click(object sender, EventArgs e)
{
System.Threading.Thread.Sleep(4000);
lblMessage.Text = "PostBack completed!!";
}

.aspx page
//And also you have to put script manager between form tag.

<asp:UpdatePanel ID="updpnlSubmit" runat="server">
<ContentTemplate>
<asp:Button ID="btnSubmit" Text="Submit" runat="server" OnClick="btnSubmit_Click" />
<asp:Label ID="lblMessage" runat="server"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
0
 
LVL 1

Author Comment

by:miyahira
ID: 39731710
Hi, mroonal. I tried your piece of code but it doesn't work. Imagebutton still keeps being enabled when processing.

Hi samirbhogayta, I can disable a Button control, but I can't do the same for an ImageButton.

It's quite strange that you can disable a Button control when processing, but it's not possible do it for ImageButton.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:SAMIR BHOGAYTA
ID: 39731757
Ok, don't worry try this

document.getElementByID(imgbtn).disabled = true;

document.getElementById(imgbtn).disabled = true;
0
 
LVL 22

Expert Comment

by:Mrunal
ID: 39738819
If still not working, then you can use simple UI blocker plug in.

like jQuery BlockUI

www.malsup.com/jquery/block/¿
0
 
LVL 1

Accepted Solution

by:
miyahira earned 0 total points
ID: 39804283
I found myself the solution:

" this.disabled=true; "  should come first.

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not Page.IsPostBack Then

           Dim strProcessScript As String = "this.disabled=true; this.value='Processing...';"
           btnProcess.Attributes.Add("onclick", (strProcessScript + ClientScript.GetPostBackEventReference(btnProcess, "").ToString))

        End If
    End Sub

Open in new window

0
 
LVL 1

Author Closing Comment

by:miyahira
ID: 40260157
Found solution by myself.
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

738 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