2

I am making a web form where the player battles the computer in a game of Nim (taking coins from piles - person to take last coin is the winner)

I have a button, where if the player pressed it I would like a input box to come up where the player enters the amount of coins he would like to take from the pile. I have been trying to figure out how to do this.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
  • Your question is a bit vague. Make sure you're familiar with how to [ask](http://stackoverflow.com/help/how-to-ask) a good question. However, there are several ways to accomplish that each with their own pros and cons. Perhaps you could tell us about the things you have tried so far? – Sacrilege Nov 20 '15 at 00:12
  • Sorry, I just need to know how to prompt a message box where the user may provide input. I know how to do it normaly in Java for example but Im a newbie when it comes to web forms I have looked at other websites for how to do it and they mention that I need to reference Microsoft.VisualBasic and then use Microsoft.VisualBasic.Interactions.InputBox(...) but it doesnt work for me, it says "interactions" is not valid. Basically I need a input box prompt that asks the user to input a number – user5583733 Nov 20 '15 at 00:24

2 Answers2

1

Based on your comments I think the JavaScript prompt method could serve you well. Here is a basic example:

var count = prompt('How many coins will you take?');

// Check to make sure they actually entered a value.
if (count) 
{
    // Do something with the result.
}
Sacrilege
  • 795
  • 9
  • 25
1

I just need to know how to prompt a message box where the user may provide input.

The difference between the disconnected nature of web development vs. application development. All of your server-side C# code has already finished executing before the web page renders in the browser. So when are you going to call this code? Also, how are you going to pass the data back to the server? A form post? An AJAX call?

I need a input box prompt that asks the user to input a number

You're right in saying that it is more complicated with a web app. In a windows app, whenever you run the C# code, whatever happens, happens at that moment. It's pretty straightforward. However, in a web app, all of the C# runs before the page is even rendered in the browser. Therefore, C# in web forms can't really pop up a window.

In order to get a popup, you'll need to do that with JavaScript. The textbox inside the popup should be an control. You can use the Ajax Control Toolkit if youre most comfortable with .NET controls. If youre comforatble with jQuery, and to post back with AJAX, I recommend the jQuery UI Dialog as the actual pop-up. Then on its close event you can make the AJAX call to the server to post the data. The POPUP that will get user input with particular the modal form

Mohit S
  • 13,723
  • 6
  • 34
  • 69