asp.net submit a form to another page Code-behind (code and HTML on different pages) _ Practical Tips
Source: Internet
Author: User
The following shows a complete example of the Code-behind file associated with the Web Forms page sending the information. Depending on whether with 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 the 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
' A TextBox control ' of ' the name '.
Return a. Text
End Get
End Property
Public ReadOnly Property LastName () as String
Get
' is ' the name of a TextBox control.
Return to 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;
protected System.Web.UI.WebControls.TextBox last;
protected System.Web.UI.WebControls.Button Button1;
public string FirstName
{
Get
{
Return a. Text;
}
}
public string LastName
{
Get
{
Return to 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"%>
<body>
<form runat= "Server" >
The Name:
<asp:textbox id= "a"
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>
[C #]
<%@ Page language= "C #" inherits= "Firstpageclass"%>
<body>
<form runat= "Server" >
The Name:
<asp:textbox id= "a"
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>
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 Informatio N. Depending on whether to 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 Pas Sed 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"%>
<body>
<form runat= "Server" >
Hello <%=FP. Firstname%> <%=FP. Lastname%>
</form>
</body>
[C #]
<%@ Page language= "C #" inherits= "Secondpageclass"%>
<%@ Reference page= "firstpage.aspx"%>
<body>
<form runat= "Server" >
Hello <%=FP. Firstname%> <%=FP. Lastname%>
</form>
</body>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.