asp.net 中將表單提交到另一頁 Code-Behind(代碼和html在不同的頁面)
更新時間:2009年04月13日 11:34:07 作者:
To send Server control values from a different Web Forms page
The following shows a complete example of the code-behind file associated with the Web Forms page sending the information. Depending on whether you use Visual Basic or C#, make sure this sample is called Firstpage.aspx.vb or Firstpage.aspx.cs, respectively.
[Visual Basic]
Imports System
Public Class FirstPageClass :
Inherits System.Web.UI.Page
Protected first As System.Web.UI.WebControls.TextBox
Protected last As System.Web.UI.WebControls.TextBox
Protected Button1 As System.Web.UI.WebControls.Button
Public ReadOnly Property FirstName() As String
Get
' first is the name of a TextBox control.
Return first.Text
End Get
End Property
Public ReadOnly Property LastName() As String
Get
' last is the name of a TextBox control.
Return last.Text
End Get
End Property
Sub ButtonClicked(sender As Object, e As EventArgs)
Server.Transfer("secondpage.aspx")
End Sub
End Class
[C#]
using System;
public class FirstPageClass : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox first;
protected System.Web.UI.WebControls.TextBox last;
protected System.Web.UI.WebControls.Button Button1;
public string FirstName
{
get
{
return first.Text;
}
}
public string LastName
{
get
{
return last.Text;
}
}
void ButtonClicked(object sender, EventArgs e)
{
Server.Transfer("secondpage.aspx");
}
}
The following shows a complete example of how to create a Web Forms page with a code-behind file to pass the values of two TextBox controls to another Web Forms page. Make sure this sample is called Firstpage.aspx.
[Visual Basic]
<%@ Page Language="VB" Inherits="FirstPageClass" %>
<html>
<head>
</head>
<body>
<form runat="server">
First Name:
<asp:TextBox id="first"
runat="server"/>
<br>
Last Name:
<asp:TextBox id="last"
runat="server"/>
<br>
<asp:Button
id="Button1"
OnClick="ButtonClicked"
Text="Go to second page"
runat=server />
</form>
</body>
</html>
[C#]
<%@ Page Language="C#" Inherits="FirstPageClass" %>
<html>
<head>
</head>
<body>
<form runat="server">
First Name:
<asp:TextBox id="first"
runat="server"/>
<br>
Last Name:
<asp:TextBox id="last"
runat="server"/>
<br>
<asp:Button
id="Button1"
OnClick="ButtonClicked"
Text="Go to second page"
runat=server />
</form>
</body>
</html>
To receive Server control values from a different Web Forms page
The following shows a complete example of the code-behind file associated with the Web Forms page receiving the information. Depending on whether you use Visual Basic or C#, make sure this sample is called Secondpage.aspx.vb or Secondpage.aspx.cs, respectively.
[Visual Basic]
Imports System
Public Class SecondPageClass
Inherits System.Web.UI.Page
Protected DisplayLabel As System.Web.UI.WebControls.Label
Public fp As FirstPageClass
Sub Page_Load()
If Not IsPostBack Then
fp = CType(Context.Handler, FirstPageClass)
End If
End Sub
End Class
[C#]
using System;
public class SecondPageClass : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label DisplayLabel;
public FirstPageClass fp;
void Page_Load()
{
if (!IsPostBack)
{
fp = (FirstPageClass) Context.Handler;
}
}
}
The following shows a complete example of how to create a Web Forms page with a code-behind file to receive the values passed from a different Web Forms page. Make sure this sample is called Secondpage.aspx
[Visual Basic]
<%@ Page Language="VB" Inherits="SecondPageClass" %>
<%@ Reference Page="firstpage.aspx" %>
<html>
<head>
</head>
<body>
<form runat="server">
Hello <%=fp.FirstName%> <%=fp.LastName%>
</form>
</body>
</html>
[C#]
<%@ Page Language="C#" Inherits="SecondPageClass" %>
<%@ Reference Page="firstpage.aspx" %>
<html>
<head>
</head>
<body>
<form runat="server">
Hello <%=fp.FirstName%> <%=fp.LastName%>
</form>
</body>
</html>
[Visual Basic]
Imports System
Public Class FirstPageClass :
Inherits System.Web.UI.Page
Protected first As System.Web.UI.WebControls.TextBox
Protected last As System.Web.UI.WebControls.TextBox
Protected Button1 As System.Web.UI.WebControls.Button
Public ReadOnly Property FirstName() As String
Get
' first is the name of a TextBox control.
Return first.Text
End Get
End Property
Public ReadOnly Property LastName() As String
Get
' last is the name of a TextBox control.
Return last.Text
End Get
End Property
Sub ButtonClicked(sender As Object, e As EventArgs)
Server.Transfer("secondpage.aspx")
End Sub
End Class
[C#]
using System;
public class FirstPageClass : System.Web.UI.Page
{
protected System.Web.UI.WebControls.TextBox first;
protected System.Web.UI.WebControls.TextBox last;
protected System.Web.UI.WebControls.Button Button1;
public string FirstName
{
get
{
return first.Text;
}
}
public string LastName
{
get
{
return last.Text;
}
}
void ButtonClicked(object sender, EventArgs e)
{
Server.Transfer("secondpage.aspx");
}
}
The following shows a complete example of how to create a Web Forms page with a code-behind file to pass the values of two TextBox controls to another Web Forms page. Make sure this sample is called Firstpage.aspx.
[Visual Basic]
<%@ Page Language="VB" Inherits="FirstPageClass" %>
<html>
<head>
</head>
<body>
<form runat="server">
First Name:
<asp:TextBox id="first"
runat="server"/>
<br>
Last Name:
<asp:TextBox id="last"
runat="server"/>
<br>
<asp:Button
id="Button1"
OnClick="ButtonClicked"
Text="Go to second page"
runat=server />
</form>
</body>
</html>
[C#]
<%@ Page Language="C#" Inherits="FirstPageClass" %>
<html>
<head>
</head>
<body>
<form runat="server">
First Name:
<asp:TextBox id="first"
runat="server"/>
<br>
Last Name:
<asp:TextBox id="last"
runat="server"/>
<br>
<asp:Button
id="Button1"
OnClick="ButtonClicked"
Text="Go to second page"
runat=server />
</form>
</body>
</html>
To receive Server control values from a different Web Forms page
The following shows a complete example of the code-behind file associated with the Web Forms page receiving the information. Depending on whether you use Visual Basic or C#, make sure this sample is called Secondpage.aspx.vb or Secondpage.aspx.cs, respectively.
[Visual Basic]
Imports System
Public Class SecondPageClass
Inherits System.Web.UI.Page
Protected DisplayLabel As System.Web.UI.WebControls.Label
Public fp As FirstPageClass
Sub Page_Load()
If Not IsPostBack Then
fp = CType(Context.Handler, FirstPageClass)
End If
End Sub
End Class
[C#]
using System;
public class SecondPageClass : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label DisplayLabel;
public FirstPageClass fp;
void Page_Load()
{
if (!IsPostBack)
{
fp = (FirstPageClass) Context.Handler;
}
}
}
The following shows a complete example of how to create a Web Forms page with a code-behind file to receive the values passed from a different Web Forms page. Make sure this sample is called Secondpage.aspx
[Visual Basic]
<%@ Page Language="VB" Inherits="SecondPageClass" %>
<%@ Reference Page="firstpage.aspx" %>
<html>
<head>
</head>
<body>
<form runat="server">
Hello <%=fp.FirstName%> <%=fp.LastName%>
</form>
</body>
</html>
[C#]
<%@ Page Language="C#" Inherits="SecondPageClass" %>
<%@ Reference Page="firstpage.aspx" %>
<html>
<head>
</head>
<body>
<form runat="server">
Hello <%=fp.FirstName%> <%=fp.LastName%>
</form>
</body>
</html>
您可能感興趣的文章:
- asp.net獲取HTML表單File中的路徑的方法
- asp.net利用后臺實(shí)現(xiàn)直接生成html分頁的方法
- Asp.net動態(tài)生成html頁面的方法分享
- 使用ASP.NET模板生成HTML靜態(tài)頁面的五種方案
- jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶端HTML標(biāo)簽后的value和text值
- ASP.net(c#) 生成html的幾種解決方案[思路]
- 使用ASP.NET 2.0 CSS 控件適配器生成CSS友好的HTML輸出
- asp.net生成HTML
- 利用ASP.NET技術(shù)動態(tài)生成HTML頁面
- asp.net 防止用戶通過后退按鈕重復(fù)提交表單
- asp.net 模擬提交有文件上傳的表單(通過http模擬上傳文件)
- ASP.NET中實(shí)現(xiàn)把form表單元素轉(zhuǎn)為實(shí)體對象或集合
- asp.net動態(tài)生成HTML表單的方法
相關(guān)文章
VS2015 Update2 構(gòu)建 Android 程序問題匯總
這篇文章主要介紹了VS2015 Update2 構(gòu)建 Android 程序問題匯總的相關(guān)資料,需要的朋友可以參考下2016-07-07asp.net中C#獲取字符串中漢字的個數(shù)的具體實(shí)現(xiàn)方法
獲取字符串中漢字原理是判斷漢字編碼然后進(jìn)行判斷是漢字還是數(shù)字了,還有就是利用正則表達(dá)式,同樣是以漢字ascii為標(biāo)準(zhǔn)來獲取2014-02-02Asp.Mvc 2.0用戶服務(wù)器驗(yàn)證實(shí)例講解(4)
這篇文章主要介紹了Asp.Mvc 2.0實(shí)現(xiàn)用戶服務(wù)器驗(yàn)證功能,需要的朋友可以參考下2015-08-08C#中遍歷各類數(shù)據(jù)集合的方法總結(jié)
C#中遍歷各類數(shù)據(jù)集合的方法,這里自己做下總結(jié):枚舉類型、遍歷ArrayList(Queue、Stack)、Winform窗體中的控件、HashTable哈希表等等,具體祥看下文2013-05-05基于.Net中的數(shù)字與日期格式化規(guī)則助記詞的使用詳解
本篇文章是對.Net中的數(shù)字與日期格式化規(guī)則助記詞的使用進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-05-05ASP.NET中實(shí)現(xiàn)jQuery Validation-Engine的Ajax驗(yàn)證
在jQuery的表變驗(yàn)證插件中Validation-Engine是一款高質(zhì)量的產(chǎn)品,提示效果非常精美,而且里面包含了AJAX驗(yàn)證功能2012-06-06