Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 533
  • Last Modified:

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
0
newbieweb
Asked:
newbieweb
  • 3
  • 3
  • 2
  • +1
3 Solutions
 
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

0
 
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

0
 
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

0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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
0
 
BTosonCommented:
Well for ASP.NET you would just put something like Button.Enabled = False in your code.
0
 
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?
0
 
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.
0
 
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

0
 
BTosonCommented:
Then the JavaScript methods above are the ebst way.  Unless you want to do it all server side with a postback!
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now