提问,初学asp,很简单的问题,不过我搞不定,请大家帮忙
工作上在用asp开发,在学校有一点c#基础,看了一大篇的理论文章后照着asp入门和精通C#與asp.Net程序設計上面的例子先实做一下,还真是让我头疼,两本书都有类似的例子,我用ie侦错就会说我的SubmitBtn_Click没有定义,但是我明明有定义,我实在搞不懂,为什么识别不了呢?我看了很多本书,语法都类似(该例子是最简单的一个),觉得好像没有什么复杂的东西,就是不明白为什么说我没有定义,我写在WebForm1.aspx.cs里面的Submit1_ServerClick里面也能按程式预期结果执行!到底是我哪里出错了啦?
代码如下:
WebForm1.aspx
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebApplication2.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
<link rel="stylesheet" href="../css/MisPrg_Style.css">
<script language="C#" runat="server">
void SubmitBtn_Click( Object sender, EventArgs e)
{
Message.Text = "Hi" + txtNam.Text + ", you selected:" + DropDownList1.SelectedItem;
}
</script>
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server" action="WebForm1.aspx">
<FONT face="新細明體">
<asp:Label id="Message" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server">姓名</asp:Label>
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 105; LEFT: 192px; POSITION: absolute; TOP: 40px"
runat="server">
<asp:ListItem Value="北京">北京</asp:ListItem>
<asp:ListItem Value="廣州">廣州</asp:ListItem>
<asp:ListItem Value="上海">上海</asp:ListItem>
</asp:DropDownList>
<asp:TextBox id="txtNam" style="Z-INDEX: 102; LEFT: 144px; POSITION: absolute; TOP: 8px" runat="server"></asp:TextBox></FONT>
<INPUT style="Z-INDEX: 103; LEFT: 16px; POSITION: absolute; TOP: 96px" type="submit" value="遞交"
runat="server" id="Submit1" name="Submit1" onclick="SubmitBtn_Click">
</form>
</body>
</HTML>
WebForm1.aspx.cs
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
namespace WebApplication2
{
/// <summary>
/// WebForm1 的摘要描述。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox txtNam;
protected System.Web.UI.WebControls.Label Message;
protected System.Web.UI.HtmlControls.HtmlInputButton SubmitBtn;
protected System.Web.UI.HtmlControls.HtmlInputButton Submit1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在這裡放置使用者程式碼以初始化網頁
}
#region Web Form 設計工具產生的程式碼
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 此為 ASP.NET Web Form 設計工具所需的呼叫。
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// 此為設計工具支援所必須的方法 - 請勿使用程式碼編輯器修改
/// 這個方法的內容。
/// </summary>
private void InitializeComponent()
{
this.Submit1.ServerClick += new System.EventHandler(this.Submit1_ServerClick);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
//
}
private void Submit1_ServerClick(object sender, System.EventArgs e)
{
//Message.Text = "Hi" + txtNam.Text + ", you selected:" + DropDownList1.SelectedItem;
}
}
}