Solved

Is it possible to disable an ImageButton when processing?

Posted on 2013-12-19
7
194 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
  • 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
Technology Partners: 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

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!

Question has a verified solution.

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

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…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …

762 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