简体   繁体   English

Web 表单上的消息和输入框

[英]Message and Input Boxes on a Web Form

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)我正在制作一个网络表单,玩家在 Nim 游戏中与计算机战斗(从一堆硬币中取出硬币 - 最后一个硬币的人是赢家)

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.我一直在试图弄清楚如何做到这一点。

Based on your comments I think the JavaScript prompt method could serve you well.根据您的评论,我认为 JavaScript 提示方法可以很好地为您服务。 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.
}

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. Web 开发与应用程序开发的脱节性质之间的区别。 All of your server-side C# code has already finished executing before the web page renders in the browser.在网页在浏览器中呈现之前,您的所有服务器端 C# 代码都已完成执行。 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? AJAX 调用?

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.您说的对,Web 应用程序更复杂。 In a windows app, whenever you run the C# code, whatever happens, happens at that moment.在 Windows 应用程序中,无论何时运行 C# 代码,无论发生什么,都会在那一刻发生。 It's pretty straightforward.这很简单。 However, in a web app, all of the C# runs before the page is even rendered in the browser.但是,在 Web 应用程序中,甚至在浏览器中呈现页面之前,所有 C# 都会运行。 Therefore, C# in web forms can't really pop up a window.因此,Web 窗体中的 C# 并不能真正弹出窗口。

In order to get a popup, you'll need to do that with JavaScript.为了获得弹出窗口,您需要使用 JavaScript 执行此操作。 The textbox inside the popup should be an control.弹出窗口内的文本框应该是一个控件。 You can use the Ajax Control Toolkit if youre most comfortable with .NET controls.如果您最熟悉 .NET 控件,则可以使用 Ajax Control Toolkit。 If youre comforatble with jQuery, and to post back with AJAX, I recommend the jQuery UI Dialog as the actual pop-up.如果您对 jQuery 感到满意,并且要使用 AJAX 回发,我推荐使用jQuery UI 对话框作为实际的弹出窗口。 Then on its close event you can make the AJAX call to the server to post the data.然后在其关闭事件上,您可以对服务器进行 AJAX 调用以发布数据。 The POPUP that will get user input with particular the modal form将使用特定的模态形式获取用户输入的 POPUP

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM