C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Code Snippets » ASP.NET WebForms »

Maintaining state using context


Posted Date: 27 Oct 2009    Resource Type: Code Snippets    Category: ASP.NET WebForms
Author: krishnavenikaladiMember Level: Gold    
Rating: 1 out of 5Points: 10



statemanagement can be done both at server side & client side
here i am giving serverside manangement using context.
context can be used with server.transfer which avoids round trip which improves performance and a little overhead at server
step 1:dempo.aspx

design demo.aspx with username,password textboxes and a button to submit
set postbackurl of button to:validate .aspx
set id of textbox1 to txtuser
set id of textbox2 to txtpwd
step2:validate.aspx


using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class validate : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//getting info from demo.aspx using request.form
string uname = Request.Form["txtuser"];
string pwd=Request .Form ["txtpwd"];
if (uname == "admin" && pwd == "admin123")
{
//setting the context with key and value
Context.Items.Add("uname", uname);
//transfering page to welcome.aspx
Server.Transfer("welcome.aspx");


}
//if not valid user this gets executed...
else

{
Response.Write("not valid...");
}
}
}


step 3:welcome.aspx
in degign view place label



public partial class welcome : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
//retrieving the context value
string name = Context.Items["uname"].ToString();
Label1.Text = " welcome "+name;
}
}



explanation:

main aim of above snippet is setting the context in one form and retrieving the value of context in othjer form.



Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Server.transfer  .  Context  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Message Box in ASP.NET C#
Previous Resource: Dealing with Detailsview control through coding
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET WebForms


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use