473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Trouble using cookie in control during Page_Init

I have a header control that I include in my .aspx page. In this control, I'm trying to retrieve a cookie value and store it into a string, but I am receiving an "Object reference not set to an instance of an object." error. Below is the code. Any help is appreciated. Thanks.

.aspx page:
Expand|Select|Wrap|Line Numbers
  1. <%@ Page Language="C#" AutoEventWireUp=true CodeFile="OrderAdmin.aspx.cs" Inherits="_Default" %>
  2. <%@ Reference Control="/custom/applications/shared_controls/reasonEntry.ascx" %>
  3. <%@ Register tagprefix="RBARC" tagname="Header" src="/custom/applications/shared_controls/header.ascx" %>
  4. <?xml version="1.0" encoding="iso-8859-1"?>
  5. <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  6. <!-- START OrderAdmin.aspx -->
  7. <html xmlns="http://www.w3.org/1999/xhtml">
  8.     <head>
  9.         <link rel="stylesheet" href="../appStyles.css" type="text/css" />
  10.         <link href="/custom/applications/Yahoo_Tools_2_5_0/yui/build/calendar/assets/calendar.css" rel="stylesheet" type="text/css" media="screen" />
  11.         <title>Order Administration</title>
  12.     </head>
  13.     <body>
  14.         <RBARC:Header ID="pageHeader" runat="server" />
  15.  
  16. <!--rest of code here-->
  17.         </body>
  18. </html>
  19.  
  20.  
C# code:
Expand|Select|Wrap|Line Numbers
  1. using System.Data;
  2. using System.Data.SqlClient;
  3. using System.Drawing;
  4. using System.Configuration;
  5. using System.Web;
  6. using System.Web.UI;
  7. using System.Web.UI.WebControls;
  8. using System.Web.UI.WebControls.WebParts;
  9. using System.Web.UI.HtmlControls;
  10. using System.Text;
  11.  
  12. public partial class Header : System.Web.UI.UserControl
  13. {
  14.     //Secure is a proprietary object of Vandamme Associates
  15.     //http://www.vandamme.com
  16.  
  17.     //constant value
  18.     const string STAFF_CODE = "RC_STAFF";
  19.     const string EXIT_CODE = "EXIT";
  20.  
  21.     private void Page_Init(object sender, System.EventArgs e)
  22.     {
  23.         //retrieves encrypted user ID and decrypts if not already created
  24.         if (Session["UserID"] == null)
  25.         {
  26.             Secure decryptUID = new Secure();
  27.             string encryptedValue = Request.Cookies["UserID"].Value;
  28.             Session["UserID"] = decryptUID.Decrypt(encryptedValue);
  29.             encryptedValue = String.Empty;
  30.         }
  31.  
  32.         if (Session["RC_User_Level"] == null)
  33.         {
  34.             CDataAccess getSelectionCodes = new CDataAccess(ConfigurationSettings.AppSettings["ConnectionStringiMIS"]);
  35.             getSelectionCodes.OpenConnection();
  36.             getSelectionCodes.SelectData("Custom_GetCodes '" + Session["UserID"] + "'");
  37.             if (getSelectionCodes.ReadNextRow())
  38.             {
  39.                 Session["RC_User_Level"] = getSelectionCodes.GetString("INTERNET_SELECTION_CODES");
  40.             }
  41.             getSelectionCodes.CloseConnection();
  42.         }
  43.     }
  44. //rest of code here
  45.  
  46. }
  47.  
May 28 '08 #1
1 1482
Looks like I solved my own problem. The control had to be put in the form tag. Bury at will.
May 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
7
by: What-a-Tool | last post by:
How does the expire date work setting it server side with asp. I know with javascript setting it client side it will be set to the clients local time, and therefore expire when the clients local...
2
by: HoustonFreeways | last post by:
Suppose I have a datagrid control which defines the showfooter property <dg:datagridconfirm id="dg_inbox" Runat="server" showfooter=false> During subsequent postbacks of the page, I change the...
2
by: somersbar | last post by:
im trying to get a table from a microsoft access database on a simple web form using visual basic.net. ive set up the database as a file dsn. this is my connection string: DBQ=C:\Program...
4
by: Jimmy M | last post by:
I've got a page that generates dropdowns and text boxes based on database data. I have them all set to auto-postback because I'll be using this with Atlas to make a more seamless user experience....
1
by: John Kotuby | last post by:
Hello again... I have tried using the SQLDatsource control as part of a user control that just conatins a Repeater and the SQLDatasource control which is designated as the Datsource for the...
5
by: Andrew Robinson | last post by:
I have a page that can load a number of different user controls. Each of these user controls inherits from a common base class and the controls are loaded based on application state, status, etc...
6
by: data | last post by:
I searched the internet and saw an old posting which has the same problem I am experiencing. The asp server doesn't recognize the variable I declare publicly in my codebehind class. The variable...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.