Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-02-2005, 10:29 PM   #1 (permalink)
sujith(ARS)
Registered User
 
Join Date: May 2005
Posts: 9
sujith(ARS) is on a distinguished road
Question how to Disable Imagebutton in Asp.net

Hi,
I'm a beginner in ASP.NET/C# development.

Does anyone know how to disable an ImageButton on ASP.NET page after the button is clicked once? Basically I dont want users to click the submit button more than once and the submit button is an Imagebutton.

I searched thru the net and found different solutions for disabling the imagebutton,But my problem is i have more than one imagebutton on my page and i want to disable all of them?

Expecting reply
Thanks in advance,
Cheers,
Sujith
sujith(ARS) is offline   Reply With Quote
Old 06-03-2005, 09:13 AM   #2 (permalink)
brendalisalowe
Registered User
 
Join Date: May 2005
Posts: 9
brendalisalowe is on a distinguished road
In your codebehind for the click event put :

Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
btnImagebutton.Enabled = False
End Sub
brendalisalowe is offline   Reply With Quote
Old 06-05-2005, 09:53 PM   #3 (permalink)
sujith(ARS)
Registered User
 
Join Date: May 2005
Posts: 9
sujith(ARS) is on a distinguished road
hi,
i tried the property "Enabled = false" of the image button .But still its not working.
//-----^^code---
private void ImgBut1_Click(object sender, System.Web.UI.ImageClickEventArgs e)
{
ImgBut2.Enabled = false;
}

//-----^^code---
Can you please tell me where i went wrong
Cheers,
Sujith
sujith(ARS) is offline   Reply With Quote
Old 06-06-2005, 08:17 AM   #4 (permalink)
brendalisalowe
Registered User
 
Join Date: May 2005
Posts: 9
brendalisalowe is on a distinguished road
Did it disable that one button after you pressed? Or it was still enabled?
brendalisalowe is offline   Reply With Quote
Old 06-06-2005, 09:04 AM   #5 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
i don't know about asp.net, but with regular html have javascript, it might look something like this:
HTML Code:
<input type="button" value="Submit" onclick="this.disable=true; this.form.submit(); />
__________________
Mike
sde is offline   Reply With Quote
Old 06-06-2005, 11:31 PM   #6 (permalink)
sujith(ARS)
Registered User
 
Join Date: May 2005
Posts: 9
sujith(ARS) is on a distinguished road
hi brenda,
I'm sorry ,it worked fine.But the matter is since it's the server script the button will be disabled only when we get back the response from the server.

But my requirement is to block the submissions from any other imgbuttons while one request is being processed.

hi sde,
your code with a little modification ,i was able to block mutiple request from same button.
Code:
private void Page_Load(object sender, System.EventArgs e)
{

this.Image1.Attributes.Add("onclick", "this.value='Please wait...';this.disabled = true;" + this.GetPostBackEventReference(this.Image1));
}

But i wasn't able to disable all buttons.

Expecting more help from all
Thanks in advance
Cheers
sujith(ARS) is offline   Reply With Quote
Old 06-07-2005, 07:54 AM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,486
sde is on a distinguished road
make a new function that disables all the buttons, .. then call that function on click.

some suedo code:
Code:
private void DisableInterface()
{
  btnSend.value = "Please Wait...";
  btnSend.disabled = true;
  txtMyField.disabled = true;
  txtMyOtherField.disabled = true;
}

 private void Page_Load(object sender, System.EventArgs e)
{
  this.Image1.Attributes.Add("onclick", "DisableInterface();" + this.GetPostBackEventReference(this.Image1));
}
like i said, it's suedo code, .. but you get the idea.
__________________
Mike
sde is offline   Reply With Quote
Old 06-17-2005, 02:17 AM   #8 (permalink)
sujith(ARS)
Registered User
 
Join Date: May 2005
Posts: 9
sujith(ARS) is on a distinguished road
hi sde,
i'm sorry for the delay in replying.its b'cos i was out of my office for some time.
sde ur code wasn't working i don't know why?the browser can't understand the other image buttons.it works fine with any other controls except imagebutton.

i was able to fix it by using GetElement by ID functionality.
Code:
__________________________________
private void Page_Load(object sender, System.EventArgs e)
{

this.Image1.Attributes.Add("onclick", "this.value='Please wait...';this.disabled = true;"
+"document.getElementById('ImgBut2').disabled = true;"+ this.GetPostBackEventReference(this.Image1));
}
__________________________________

thanks for the Helps
Cheers,
Sujith
sujith@arssoftware.com
sujith(ARS) is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Checking a flag in Opened ASP.net page Continously ! mechtech MS Technologies ( ASP, VB, C#, .NET ) 1 04-19-2005 12:37 PM
mysql and ASP.Net popyweb MS Technologies ( ASP, VB, C#, .NET ) 3 12-04-2004 08:57 PM
new to asp.net rmill9681 MS Technologies ( ASP, VB, C#, .NET ) 5 11-29-2004 08:05 AM
disable telnet? sde Linux / BSD / OS X 5 02-07-2003 03:25 PM


All times are GMT -8. The time now is 02:08 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting