還想請問一下: 我的aspx文件是這樣的:只是想點實現點button的時候輸出“abcdbc ”但我只會在一個頁裡去實現,即把它寫在aspx文件中。如果我要寫在.vb文件中怎麼辦? <%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="first.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.0"> <meta name="CODE_LANGUAGE" content="Visual Basic 7.0"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <FONT face="新細明體"> <asp:Button id="Button1" runat="server" Text="Button" OnClick="abc"></asp:Button> </FONT> </form> <div id="ab"></div> <script language="vb" runat="server"> Public Sub abc(ByVal Sender As Object, ByVal E As EventArgs) Response.Write("abcdbc") End Sub </script> </body> </HTML>aspx.vb文件是這樣的: Public Class WebForm1 Inherits System.Web.UI.Page Protected WithEvents Button1 As System.Web.UI.WebControls.Button Protected WithEvents Label1 As System.Web.UI.WebControls.Label#Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End SubEnd Class
.aspx.vb是干你想干的事情所需要的代码,比如提交一个表单……
//以我的道行就知道这个……
###.aspx页面文件;
asp.net也兼容asp的编写方式,你可以把代码写在页面文件中
編輯:###.aspx.vb可以達到編輯###.aspx同樣的效果,不過方法不同而已?
.aspx.vb在编译时生成.dll文件,运行时只要有dll就可以了,这样别人就看不到你的程序了。
主要是一些界面元素
###.aspx.vb
可以动态改变界面元素,还可以用一些方法,使想你要的结果。
我的aspx文件是這樣的:只是想點實現點button的時候輸出“abcdbc ”但我只會在一個頁裡去實現,即把它寫在aspx文件中。如果我要寫在.vb文件中怎麼辦?
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm1.aspx.vb" Inherits="first.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.0">
<meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<FONT face="新細明體">
<asp:Button id="Button1" runat="server" Text="Button" OnClick="abc"></asp:Button>
</FONT>
</form>
<div id="ab"></div>
<script language="vb" runat="server">
Public Sub abc(ByVal Sender As Object, ByVal E As EventArgs)
Response.Write("abcdbc")
End Sub
</script>
</body>
</HTML>aspx.vb文件是這樣的:
Public Class WebForm1
Inherits System.Web.UI.Page
Protected WithEvents Button1 As System.Web.UI.WebControls.Button
Protected WithEvents Label1 As System.Web.UI.WebControls.Label#Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
End Sub Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) End SubEnd Class
1.去掉OnClick="abc"
2.双击这个Button就是对应的事件,在里面写即可
3.注意,编写完要编译才能运行。
和vb是很像的。
不要在aspx上乱点,以免生成多余的代码。