从另一个页面获取数据 [英] Get data from another page

查看:101
本文介绍了从另一个页面获取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在尝试设计一个项目.人们拥有帐户,并且帐户具有不同的权限,因此当他们登录时,代码会将其ID转到用户不同的页面.我将ID发布到网页,但知道我可以在目标页面上获取此ID.您能帮我吗?

Hi,
I am trying to design a project. People have account and accounts have different authority so when they sign in, the code forward the user different page with their id. I post id to webpage but know i can get this id on destined page. Can you help me?

推荐答案

解决方案1:
使用查询字符串

源代码形式
solution 1:
Using Query string

source-form
private void btnSubmit_Click(object sender, System.EventArgs e)
{
Response.Redirect("Webform2.aspx?Id=" +
this.txtid.Text);
}



目的地表格



Destination-form

private void Page_Load(object sender, System.EventArgs e)
{
this.txtId.Text = Request.QueryString["Id"];
}




解决方案2:
使用会话
源代码形式




Solution 2:
Using Session
source-form

private void btnSubmit_Click(object sender, System.EventArgs e)
{
    Session["Id"]=this.txtid.Text;
}



目的地表格



Destination-form

private void Page_Load(object sender, System.EventArgs e)
{
this.txtId.Text = Session["Id"];
}



祝您编码愉快!
:)



Happy Coding!
:)


要将数据从一页传输到另一页或通过asp.net中的整个应用程序传输,有不同的方法.

1)使用会话
2)使用Cookies
3)使用QueryString


1)使用会话 SessionInfo [ ^ ]
您可以将简单数据和复杂数据存储到会话对象,会话将维护服务器端.
For transferring data from one page to another page or through out entire application in asp.net, there are different different way.

1) Using Sessions
2) Using Cookies
3) Using QueryString


1) Using Session SessionInfo[^]
you can store simple as well as Complex data to session object, session will maintain server side.
//Declaring and Storing value to session variable
//Sysntax
Session["SESSIONNAME"] = value;
e.g.
//Use of Session
//Setting Value to Session variable
Session["USER_NAME"] = "Tejas Vaishnav";

//Accessing Value from Session variable
string _userName = Session["USER_NAME"].toString();



2)使用Cookie CookieInfo [ ^ ]
Cookie是用于存储数据客户端的小型文本文件.



2) Using Cookie CookieInfo[^]
Cookie is a small text file used to store data client side.

//Syntax
//Creating and storing value to cookie
HttpCookie _cookie = new HttpCookie("COOKIE NAME");
_cookie["COOKIE NAME"] = "Value";
Response.Cookies.Add(_cookie);

//Retrieves value from Cookie
HttpCookie _cookieValue = Request.Cookies["COOKIE NAME"];
string _name =  _cookieValue["COOKIE NAME"].toString();


e.g.
//Use
HttpCookie _cookie = new HttpCookie("USER_NAME");
_cookie["USER_NAME"] = "Tejas Vaishnav";
Response.Cookies.Add(_cookie);

//Accessing value from cookies
HttpCookie _cookieValue = Request.Cookies["USER_NAME"];
string _userName =  _cookieValue["USER_NAME"].toString();



3)使用QueryString QueryStringInfo [



3) Using QueryString QueryStringInfo[^]
Query string is a collection of Key and value pair passed through your page URL.

//Declaration syntax
Response.Redirect("~/Default.aspx?name=tejas&lastName=vaishnav");

//Example of Query string
http://www.xyz.com/Default.aspx?name=tejas&lastName=vaishnav

//Accessing data from Query string
string _name = Request.QueryString["Name"].toString();
string _lastName = Request.QueryString["LastName"].toString();



这些方法可以将数据从一页传递到另一页.



these all the way you can pass data from one page to another page.


最简单的方法是实现成员身份:
The easiest way is to implement membership: Introduction to Membership[^] - the link will show you how, and also how to use it when they are signed in.


这篇关于从另一个页面获取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆