This is a discussion on how to store and retrieve data from cookies within the ASP and ASP.NET Programming forums, part of the Web Development category; //This example shows that how to store and retrieve data from cookies. // Offshore Software Development Company India, Software Development India ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| //This example shows that how to store and retrieve data from cookies. // Offshore Software Development Company India, Software Development India private void Page_Load(object sender, System.EventArgs e) { // Put user code to initialize the page here if(!IsPostBack) { if(Request.Cookies["UserCook"] != null) { chkRemember.Checked = true; HttpCookie cook = Request.Cookies["UserCook"]; txtUserName.Text = cook["UserName"].ToString(); } } } private void btnSubmit_Click(object sender, System.EventArgs e) { try { if(chkRemember.Checked == true) { if(Request.Browser.Cookies == true) { HttpCookie loginCook = new HttpCookie("UserCook"); loginCook["UserName"] = txtUserName.Text.Trim(); loginCook.Expires = DateTime.MaxValue; Response.Cookies.Add(loginCook); } else { lblErr.Text = "Please enable your cookies in Internet option in Explorer."; } } if(txtUserName.Text.Trim() == "developer" && txtPwd.Text.Trim() == "developer") { Session["UserId"] = txtUserName.Text.Trim(); Response.Redirect("Querystring.aspx?Usertype=Web Developer"); } else if(txtUserName.Text.Trim()=="admin" && txtPwd.Text.Trim()== "admin") { Session["UserId"] = txtUserName.Text.Trim(); string str = Server.UrlEncode("Administrator+"); Response.Redirect("Querystring.aspx?UserType="+str ); } else { lblErr.Text = "Invalid user id and password."; } } catch(Exception ex) { Response.Write(ex.Message); } } } }
__________________ Offshore Software Development Company India, Software Development India Last edited by Booom : 07-23-2007 at 01:46 AM. Reason: link publicity |
| Sponsored Links |
| |||
| Hi, The above coding is very usefull for me...Here i need to store and retrieve the cookie in asp.net using javascript.. Can u assist me.... Thanks in advance
__________________ H2O Without us, no one can survive.. |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Store and retrive flash cookies | oxygen | Flash Actionscript Programming | 4 | 08-22-2007 11:58 PM |
| How to Store and Retrieve the values in server side caches in ASP.NET? | oxygen | ASP and ASP.NET Programming | 1 | 07-23-2007 01:14 AM |
| How to retrieve SIM card data using j2me? | mobilegeek | J2ME | 0 | 07-22-2007 10:22 PM |
| Store and Retrieve the values in cookies in ASP.NET | oxygen | ASP and ASP.NET Programming | 0 | 07-20-2007 12:23 AM |
| how to retrieve the data after commit statement | vadivelanvaidyanathan | Database Support | 3 | 03-21-2007 05:49 AM |