怎样从asp.net 中将表单提交到另一页 Code-Behind(代码和html在不同的页面)

来源:爱站网时间:2021-11-01编辑:网友分享
怎样从asp.net 中将表单提交到另一页 Code-Behind(代码和html在不同的页面)?这个问题你知道正确的答案吗?不知道的别担心,爱站技术小编会帮助你,这不,用一篇文章详细的给你介绍一下内容。

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]






First Name:
runat="server"/>


Last Name:
runat="server"/>


id="Button1"
OnClick="ButtonClicked"
Text="Go to second page"
runat=server />



[C#]






First Name:
runat="server"/>


Last Name:
runat="server"/>


id="Button1"
OnClick="ButtonClicked"
Text="Go to second page"
runat=server />



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]







Hello



[C#]







Hello


以上内容就是爱站技术频道小编为大家分享的怎样从asp.net 中将表单提交到另一页 Code-Behind(代码和html在不同的页面),看完以上分享之后,大家应该都知道怎么去操作这些了吧。

上一篇:怎么操作DiscuzNT 论坛与主站的同步登录与退出

下一篇:怎么把c# 读取文件内容存放到int数组 array.txt里面

您可能感兴趣的文章

相关阅读

热门软件源码

最新软件源码下载