Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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
ASP.net中的“提交”按钮_Asp.net_Forms_Submit - Fatal编程技术网

ASP.net中的“提交”按钮

ASP.net中的“提交”按钮,asp.net,forms,submit,Asp.net,Forms,Submit,我是.NET新手,正在尝试基本功能。我在放置提交按钮时出错。请通读代码,让我知道我使用的提交按钮语法是否错误 代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>My First web page</title> </head> <body> <form id="form1" runat="server

我是.NET新手,正在尝试基本功能。我在放置提交按钮时出错。请通读代码,让我知道我使用的提交按钮语法是否错误

代码:

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>My First web page</title>
</head>
<body>
    <form id="form1" runat="server" >
    <div style="position:absolute">


        First Name :<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <br/>
        Last Name :<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
        <asp:Button OnClick="submit" Text="submit" runat="server" />
    </div>
    </form>
</body>
</html>

谢谢。

您必须向OnClick提供服务器端OnClick处理程序,而且提交可能未定义为处理程序。这说明OnClick事件处理程序是如何与按钮连接的。您还需要为按钮提供ID

从按钮中删除OnClick属性。在VS designer中打开表单双击VS designer中的按钮,它将为您生成处理程序。您可以在中找到模式

在生成事件处理程序之后,您将得到如下内容

代码隐藏

HTML(aspx)



子提交(发件人作为对象,e作为事件参数)
lbl1.Text=“您的名字是”&txt1.Text
端接头
输入您的姓名:


@Midhun T:检查并让我知道你能解释一下你做了什么吗?双击submit按钮并放置code Sub submit(发件人作为对象,e作为事件参数)lbl1.Text=“你的名字是”&txt1.Text End Sub双击按钮后,我得到了代码:using System;使用System.Collections.Generic;使用System.Linq;使用System.Web;使用System.Web.UI;使用System.Web.UI.WebControl;命名空间WebApplication1{公共部分类WebForm1:System.Web.UI.Page{受保护的无效页面{加载(对象发送方,事件参数e){}受保护的无效按钮{}单击(对象发送方,事件参数e){}}}我应该在此处进行哪些更改,并请解释原因。错误消失了吗?你所说的“我应该在这里做什么更改并请解释原因”是什么意思?是的,错误已经消失了。非常感谢。我不明白这个错误是如何解决的。是因为我删除了OnClick还是因为我在设计视图中双击了按钮?当我双击按钮时,为什么会出现一个新的“.cs”页面?双击是为了创建事件处理程序。请参阅此处的详细信息,错误是由于缺少处理程序定义。
Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. 

Compiler Error Message: CS1061: 'ASP.webform1_aspx' does not contain a definition for 'submit' and no extension method 'submit' accepting a first argument of type 'ASP.webform1_aspx' could be found (are you missing a using directive or an assembly reference?)
void yourButtonId_Click(Object sender, EventArgs e)
{

}
<asp:Button ID="yourButtonId" OnClick="yourButtonId_Click" Text="submit" runat="server" />
<script  runat="server">
Sub submit(sender As Object, e As EventArgs)
   lbl1.Text="Your name is " & txt1.Text
End Sub
</script>

<!DOCTYPE html>
<html>
<body>

<form runat="server">
Enter your name:
<asp:TextBox id="txt1" runat="server" />
<asp:Button OnClick="submit" Text="Submit" runat="server" />
<p><asp:Label id="lbl1" runat="server" /></p>
</form>

</body>
</html>