1.Request.QueryString
在传值的页面(aspx.cs页面):
Response.Redirect("QueryStringPage.aspx?Data=" + Server.UrlEncode(DataToSendTextBox.Text));
在接收值的页面(.net前端页面):
<%=Server.UrlDecode(Request.QueryString["Data"]) %>
2.HttpPost
在传值的页面(aspx页面):
<form id="form1" runat="server"> <div> <h1>Source Page</h1> Data to send: <asp:TextBox ID="DataToSendTextBox" runat="server" Text="Hello World!"></asp:TextBox><br /><br /> <asp:Button ID="HttpPostButton" runat="server" Text="Use HttpPost" PostBackUrl="~/HttpPostPage.aspx"/><br /><br /> </div> </form>
在接收的页面(aspx页面):
<%=Request.Form["DataToSendTextBox"] %>
在接收的页面(aspx.cs页面):
System.Text.StringBuilder displayValues = new System.Text.StringBuilder(); System.Collections.Specialized.NameValueCollection postedValues = Request.Form; String nextKey; for (int i = 0; i < postedValues.AllKeys.Length; i++) { nextKey = postedValues.AllKeys[i]; if (nextKey.Substring(0, 2) != "__") { displayValues.Append("<br>"); displayValues.Append(nextKey); displayValues.Append(" = "); displayValues.Append(postedValues[i]); } } ReceivedDataLabel.Text = displayValues.ToString();
上述代码中,postedValues[i]为获取到的所接收的值
3.Session State
传值页面(aspx.cs页面):
Session["Data"] = DataToSendTextBox.Text; Response.Redirect("SessionStatePage.aspx");
接收值页面(aspx页面):
<%=Session["Data"] %>
4.Public Properties
传值页面(aspx.cs页面):
public string DataToSend { get { return DataToSendTextBox.Text; } }
Server.Transfer("PublicPropertiesPage.aspx"); 接收值页面(aspx页面):
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
<%=PreviousPage.DataToSend %>5.Control Info
传值页面(aspx.cs页面)
public string DataToSend { get { return DataToSendTextBox.Text; } }
Server.Transfer("ControlInfoPage.aspx"); 接收值的页面(aspx页面)
<%@ PreviousPageType VirtualPath="~/Default.aspx" %>
<asp:Label ID="DataReceivedLabel" runat="server" Text="Label"></asp:Label> 接收值的页面(aspx.cs页面)
protected void Page_Load(object sender, EventArgs e) { var textbox = PreviousPage.FindControl("DataToSendTextbox") as TextBox; if (textbox != null) { DataReceivedLabel.Text = textbox.Text; } }上述代码中,textbox.Text即为传送过来的值
时间: 2024-11-12 21:39:32