Asp.net submits the form to another page Code-Behind (Code and html are on different pages)

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 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 processing 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>

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.