我想问一下,如何实现两个页面之间的传数。我是这样做的请各位指教(VB。NET)
第一个页面:
Public ReadOnly Property page_action() As String
Get
'Return s_page_action
Return "add"
End Get
End Property
然后
Server.Transfer("WebForm2.aspx")
第二个页数应如何写呢,请各位帮忙
...全文
6015打赏收藏
两个页面之间如何传数
我想问一下,如何实现两个页面之间的传数。我是这样做的请各位指教(VB。NET) 第一个页面: Public ReadOnly Property page_action() As String Get 'Return s_page_action Return "add" End Get End Property 然后 Server.Transfer("WebForm2.aspx") 第二个页数应如何写呢,请各位帮忙
' Visual Basic
Public ReadOnly Property Property1() As String
Get
Return TextBox1.Text
End Get
End Property
// C#
public string Property1
{
get
{
return TextBox1.Text;
}
}
通过调用 Server 对象(HttpServerUtility 类)的 Transfer 方法调用下一页,并向其传递要将信息传递到的页的 URL。
以下示例显示如何从事件处理程序中调用名为 WebForm2 的页(在同一项目中):
' Visual Basic
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Server.Transfer("Webform2.aspx")
End Sub
' Visual Basic
' Put immediately after the Inherits statements
' at the top of the file
Public sourcepage As WebForm1
// C#
// Put immediately after the opening brace of the class
public class WebForm3 : System.Web.UI.Page
{
public WebForm1 sourcepage;
// etc.
在 Page_Load 处理程序中,从 Context.Handler 对象(IHttpHandler 接口)中获取源页,然后向其分配在第 1 步创建的变量。必须将该处理程序对象转换为源页类的类型。
注意 只应在该页首次运行(即首次从源页中调用该页)时执行此逻辑。
从源页中获取属性值,并按照使用任何对象属性的方式来使用这些属性值。
注意 如果要在除第一页初始化阶段之外的任何页处理阶段中使用属性值,则务必要保存这些属性值(例如以视图状态保存)。有关详细信息,请参见 Web 窗体状态管理介绍。
完整的 Page_Load 处理程序可能类似于如下所示:
' Visual Basic
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
sourcepage = CType(Context.Handler, WebForm1)
Label1.Text = sourcepage.Property1
End If
End Sub
第二页就是这样写:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
'得到第一页的对象
sourcepage = CType(Context.Handler, WebForm1)
'读取页面的属性
Label1.Text = sourcepage.Property1
End If
End Sub