c# - 如何在 Asp.net 中将值从一种形式传递到另一种形式

标签 c# .net asp.net visual-studio

如何在 Asp.net 中将值从一种形式传递到另一种形式?

能举个例子吗?


我明白了。感谢大家的回复。

在源代码中我必须写

protected void btnAdd_Click(object sender, EventArgs e)
{
    Session["name"] = textBox.Text;
    Server.Transfer("WebForm1.aspx");
}

在目标中我必须写

void Page_Load(object sender, EventArgs e)
{
    answer.Text = Session["name"].ToString();
    Session.Remove("name");
}

最佳答案

客户端技术: 1)查询字符串 2) cookies

查询字符串: 对于发送:

字符串名称="abc"; Response.Redirect("Page2.aspx?name= "+name);

获得: 在 Page2.aspx 上 string name=Response.QueryString.GetValue("name");

对于您可以使用的 cookie 发送: HttpCookie h=new HttpCookie(); h.Name="姓名"; h.Value="abc"; Response.Cookies.Add(h) ;

得到: string name = Request.Cookies('name');

服务器端技术: 1) session

对于设置: Session["Name"] = "Abc";

获得: string str = Session["Name"].ToString();

在 session 中,您可以传递任何对象类型。

关于c# - 如何在 Asp.net 中将值从一种形式传递到另一种形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6746860/

相关文章:

C# 获取字符串中两个字符之间的字符串

c# - 使用 HttpPost 将文档上传到服务器

c# - 文件上传错误 WCF WEB API(预览版 6): Cannot write more bytes to the buffer than the configured maximum buffer size: 65536

c# - 在 ASP.NET 中使用文件 uploader 将图像上传到 Azure Blob?

c# - 更新面板中的计时器

javascript - 将 scrapy 与 javascript __doPostBack 方法结合使用时出现问题

c# - 表达式树问题 - 如何将实例方法转换为 Func

C# 多个项目引用同一个 dll - 更新 dll 的简单方法是什么?

c# - 使用 linq 或 lambda 表达式进行对象分组

c# - 为什么我下载文件的代码会生成损坏的 PDF?