I need to enable and disable a button using JavaScript, ASP and ASP.NET

I have a simple request that I would like to create a test program which uses JavaScript to disable (then re-enable) an ASP button.  I would also like to see how the same thing's done with ASP.NET.

Maybe someone could post a simple program with two buttons where when you click one, it enables the other and disables the button you clicked.   I would love to see that in ASP as well as ASP.NET.

I would be happy to write it, but I think it may be easier for someone to write than explain.

Thanks,
newbieweb
newbiewebSr. Software EngineerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

bluV11tCommented:
Hi!
Here is the JavaScript version:


<input type="button" value="Disable" onclick="JavaScript: document.getElementById('third_button').disabled = true;" />
<input type="button" value="Enable" onclick="JavaScript: document.getElementById('third_button').disabled = false;" />
<input type="submit" value="3. button" id="third_button" />

Open in new window

Tomarse111Commented:
Here you go. Two buttons, one disables the other onclick:
<script type="text/javascript">
function bttns(id) { 
	if(id=="a"){
		document.getElementById('bttn2').disabled=false;
		document.getElementById('bttn1').disabled=true;
	}else{
		document.getElementById('bttn2').disabled=true;
		document.getElementById('bttn1').disabled=false;	
	}
}
</script>
<body id="doc">
	<input id="bttn1" type="button" value="Button 1" onclick="bttns('a');">
	<input disabled="disabled" id="bttn2" type="button" value="Button 2" onclick="bttns('b');">
</body>

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bluV11tCommented:
Sorry, I misread your question. Here's a new version:
<input type="button" value="First" id="first_button" onclick="JavaScript: document.getElementById('first_button').disabled = true;document.getElementById('second_button').disabled = false;" />
<input type="button" value="Second" id="second_button" onclick="JavaScript: document.getElementById('first_button').disabled = false;document.getElementById('second_button').disabled = true;" />

Open in new window

Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

newbiewebSr. Software EngineerAuthor Commented:
Tomarse111,

I used your code sinnce it was all in one place.  Could you do the same thing with ASP.NET? I'm trying to learn both technologies at the same time...


newbieweb
BTosonCommented:
Well for ASP.NET you would just put something like Button.Enabled = False in your code.
newbiewebSr. Software EngineerAuthor Commented:
Where would you put that line?  LLike this?

document.getElementById('bttn2').Enable = false;

what about the controls?  How are they different?
BTosonCommented:
If you are referring to ASP.NET then it would go in your code behind.
This change would occur on the server and not on the client directly.
newbiewebSr. Software EngineerAuthor Commented:
I see.  Code behind makes it easy for me to do: I'm a WinForms C# developer.  But I need to learn the HTML side of ASP.NET.

Thanks,
newbieweb

BTosonCommented:
Then the JavaScript methods above are the ebst way.  Unless you want to do it all server side with a postback!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.