Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/31.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用c语言显示消息#_C#_Asp.net - Fatal编程技术网

C# 用c语言显示消息#

C# 用c语言显示消息#,c#,asp.net,C#,Asp.net,我是C#,ASP.NET的初学者。 我想要的是,当单击“提交”按钮时,需要显示一条消息“您的注册成功”。 但当我点击这里时,没有显示任何内容,但它在其他电脑上以相同的代码显示消息。 有人能帮我吗?我的项目中是否存在任何配置错误 代码如下: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebC

我是C#,ASP.NET的初学者。 我想要的是,当单击“提交”按钮时,需要显示一条消息“您的注册成功”。 但当我点击这里时,没有显示任何内容,但它在其他电脑上以相同的代码显示消息。 有人能帮我吗?我的项目中是否存在任何配置错误

代码如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Windows.Forms;
public partial class Registration : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

}
protected void submit_Click(object sender, EventArgs e)
{
    Response.Write("Your registration is succesful"); // Not displaying
    //MessageBox.Show("Test Display");
}
}

ASP.NET

<form id="form1" runat="server">
    <div>

    </div>
    <table class="style1">
        <tr>
            <td class="style3">
                Username</td>
            <td class="style6">
                <asp:TextBox ID="uname" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td class="style8">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" 
                    ControlToValidate="uname" ErrorMessage="Username is required" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style3">
                Email</td>
            <td class="style6">
                <asp:TextBox ID="email" runat="server" Width="180px"></asp:TextBox>
            </td>
            <td class="style8">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" 
                    ControlToValidate="email" ErrorMessage="Email is required" ForeColor="Red"></asp:RequiredFieldValidator>
                <br />
                <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server" 
                    ControlToValidate="email" ErrorMessage="You must enter the valid email id" 
                    ForeColor="Red" 
                    ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"></asp:RegularExpressionValidator>
            </td>
        </tr>
        <tr>
            <td class="style3">
                Password</td>
            <td class="style6">
                <asp:TextBox ID="pass" runat="server" TextMode="Password" Width="180px"></asp:TextBox>
            </td>
            <td class="style8">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" 
                    ControlToValidate="pass" ErrorMessage="Password is required" ForeColor="Red"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style3">
                Confirm Password</td>
            <td class="style6">
                <asp:TextBox ID="passr" runat="server" TextMode="Password" Width="180px"></asp:TextBox>
            </td>
            <td class="style8">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server" 
                    ControlToValidate="passr" ErrorMessage="Confirm password is required" 
                    ForeColor="Red"></asp:RequiredFieldValidator>
                <br />
                <asp:CompareValidator ID="CompareValidator1" runat="server" 
                    ControlToCompare="pass" ControlToValidate="passr" 
                    ErrorMessage="Both passwords must be same" ForeColor="Red"></asp:CompareValidator>
            </td>
        </tr>
        <tr>
            <td class="style3">
                Country</td>
            <td class="style6">
                <asp:DropDownList ID="country" runat="server" Width="180px">
                    <asp:ListItem>Select Country</asp:ListItem>
                    <asp:ListItem>USA</asp:ListItem>
                    <asp:ListItem>UK</asp:ListItem>
                    <asp:ListItem>GERMANY</asp:ListItem>
                    <asp:ListItem>FRANCE</asp:ListItem>
                    <asp:ListItem>INDIA</asp:ListItem>
                </asp:DropDownList>
            </td>
            <td class="style8">
                <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server" 
                    ControlToValidate="country" ErrorMessage="Select a country name" 
                    ForeColor="Red" InitialValue="Select Country"></asp:RequiredFieldValidator>
            </td>
        </tr>
        <tr>
            <td class="style4">
            </td>
            <td class="style7">
                <asp:Button ID="submit" runat="server" Text="Submit" />
            </td>
            <td class="style5">
                <input id="Reset1" type="reset" value="reset" /></td>
        </tr>
        <tr>
            <td class="style2">
                &nbsp;</td>
            <td class="style6">
                &nbsp;</td>
            <td>
                &nbsp;</td>
        </tr>
    </table>
    </form>

用户名
电子邮件

密码 确认密码
国家 选择国家 美国 英国 德国 法国 印度
您需要了解服务器端和客户端之间的区别

服务器端是指服务器上发生的一切(例如ASP、ASP.NET、PHP),用于创建发送到浏览器的HTML。它还处理用户提交回内容(回发)时浏览器返回的信息

客户端是指一旦收到HTML,或当用户在页面上执行某些操作(如单击元素)时,浏览器上发生的一切

您正在尝试运行Windows应用程序样式的MessageBox。在服务器上显示。。。那是行不通的

如果希望浏览器显示“警报”窗口(有点像
消息框
),则需要向浏览器发送客户端脚本。试试这个

protected void submit_Click(object sender, EventArgs e)
{
    Response.Write("Your registration is succesful");
    var script = "window.alert('Test Display');";
    ClientScript.RegisterStartupScript(this.GetType(), "message", script, true);
}

根据OP的评论

我的问题是回复。写下(“您的注册成功”);它不起作用了

不要使用
响应。编写
使用
控件(这样可以将控件精确定位在需要的位置),并设置其
.Text
属性(请记住,此属性将保留在回发中,因此您可能需要清除它)


您还可以使用
,它不仅允许您定位它,还可以包括
.CssClass
.Style
属性以获得更好的格式设置。

如果您想显示确认消息框,请尝试在.aspx页面上使用jquery。您可以添加这样的函数

function confirmationAccept() {
    return confirm("Accept?");
}
然后在客户端上添加属性,如下所示:

<asp:Button ID="addButton" runat="server" Text="Add"  OnClientClick="return confirmationAccept()">


您可以使用
ClientScript显示javascript警报消息。RegisterStartupScript

MessageBox
仅在web服务器上运行,不应与asp.NET一起使用在哪台计算机上您认为应该显示消息框?事实上,您认为这段代码做了一些有用的事情,这表明您可能对ASP.NET的工作方式有概念上的问题。ASP在向客户端发送文本的服务器上运行代码。那个模型清楚吗?在
ASP.NET
中没有
MessageBox.Show
,真的很抱歉,我犯了一个大错误,我忘了删除MessageBox.Show(“测试显示”);我的问题是回复。写下(“您的注册成功”);真的很抱歉,我犯了一个大错误,我忘了删除MessageBox.Show(“测试显示”);我的问题是回复。写下(“您的注册成功”);对于你的考虑和时间来说,它不起作用。真的很抱歉,我犯了一个很大的错误,我忘了删除MessageBox.Show(“测试显示”);我的问题是回复。写下(“您的注册成功”);真的很抱歉,我犯了一个大错误,我忘了删除MessageBox.Show(“测试显示”);我的问题是回复。写下(“您的注册成功”);它不起作用了