Click here to Skip to main content
15,896,201 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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?
Posted
Comments
AshishChaudha 27-Jul-12 6:45am    
What you have done so far..show us..and where you got stuck??

solution 1:
Using Query string

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


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



Solution 2:
Using Session
source-form
C#
private void btnSubmit_Click(object sender, System.EventArgs e)
{
    Session["Id"]=this.txtid.Text;
}


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


Happy Coding!
:)
 
Share this answer
 
Comments
Prasad_Kulkarni 27-Jul-12 7:06am    
Good work, 5'ed!
Aarti Meswania 27-Jul-12 7:07am    
thanks :)
sandeep nagabhairava 27-Jul-12 7:28am    
nice explanation...
Aarti Meswania 27-Jul-12 7:29am    
thank you :)
sesenyg 27-Jul-12 8:03am    
thanks a lot:)
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.
C#
//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) Using Cookie CookieInfo[^]
Cookie is a small text file used to store data client side.
C#
//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) Using QueryString QueryStringInfo[^]
Query string is a collection of Key and value pair passed through your page URL.
C#
//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.
 
Share this answer
 
Comments
sesenyg 27-Jul-12 8:03am    
QueryString method solved my problem. Thanks:))
Tejas Vaishnav 27-Jul-12 9:08am    
that's good to here that your problem is solved.
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900