Retrieving Session in a User Control

Discussion in 'ASP .Net' started by =?Utf-8?B?RGlmZmlkZW50?=, Nov 29, 2004.

  1. Hello All,

    I have a nested user control i.e., Control B which is loaded from Control A.
    Control A is itself dynamically loaded from a web form.

    Control A has a "Save" button which loads the Control B dynamically. Now in
    Control B there is a "Return" button which calls the method A of Control A.
    In method A, a session variable is being retrieved. My problem is whenever
    the control is passed back to the Control A, error is being thrown at the
    line where session is being retrieved.

    Can anyone please suggest me on how to go about this problem? Is there any
    other way to access session from user controls?

    Thanks for your pointers!!!
     
    =?Utf-8?B?RGlmZmlkZW50?=, Nov 29, 2004
    #1
    1. Advertising

  2. Please show us the line of code that is causing the error message and give
    us the error message.

    --
    Steve C. Orr, MCSD, MVP
    http://Steve.Orr.net


    "Diffident" <> wrote in message
    news:...
    > Hello All,
    >
    > I have a nested user control i.e., Control B which is loaded from Control
    > A.
    > Control A is itself dynamically loaded from a web form.
    >
    > Control A has a "Save" button which loads the Control B dynamically. Now
    > in
    > Control B there is a "Return" button which calls the method A of Control
    > A.
    > In method A, a session variable is being retrieved. My problem is whenever
    > the control is passed back to the Control A, error is being thrown at the
    > line where session is being retrieved.
    >
    > Can anyone please suggest me on how to go about this problem? Is there any
    > other way to access session from user controls?
    >
    > Thanks for your pointers!!!
    >
     
    Steve C. Orr [MVP, MCSD], Nov 29, 2004
    #2
    1. Advertising

  3. Hi Steve,

    Please find the code snippets below:

    Method A inside User Control A:

    -------------------------------------------
    public void LoadDataGrid()
    {
    DataSet ds = new DataSet();
    string[] sqlString = new string[2];

    sqlString[0] = " SELECT REQ_CLIENT.ID,FIRSTNAME ||' '|| LASTNAME
    NAME,COMPANY,COUNTY, "+ " DECODE(REQ_CLIENT.ID,BILLING_CONTACT,1,0)
    IS_BILLING_PERSON "+ " FROM REQ_CLIENT,REQ_QUEUE WHERE "+
    " REQ_QUEUE.ID = ID_REQ_QUEUE AND "+" ID_REQ_QUEUE=
    "+Session["ID_REQ_QUEUE"].ToString()+" ORDER BY UPPER(LASTNAME) ";

    .........
    .........
    .........
    -------------------------------------------------

    The way I am calling the User Control A from Control B is as follows by
    instantiating an object of the Control class:

    secure.NewDiagnostics.Requester.Contacts1 parentControl = new
    secure.NewDiagnostics.Requester.Contacts1();

    if(this.Parent!=null)
    {
    parentControl.LoadDataGrid();
    }

    So when control goes back to the LoadDataGrid method in the parent control I
    get the following error:

    ErrorMessage:
    ----------------
    Object reference not set to an instance of an object.

    ErrorSource: System.Web

    ErrorTargetSite:
    ----------------
    System.Web.SessionState.HttpSessionState get_Session()

    ErrorTrace:
    ----------------
    at System.Web.UI.UserControl.get_Session()
    at secure.NewDiagnostics.Requester.Contacts1.LoadDataGrid() in
    c:\inetpub\wwwroot\intranet.pdis.org\diagnostics\submitter\contacts1.ascx.cs:line 522

    At line 522, there is an SQL query which is accessing a session variable.

    Any pointers?

    Thanks!!

    "Steve C. Orr [MVP, MCSD]" wrote:

    > Please show us the line of code that is causing the error message and give
    > us the error message.
    >
    > --
    > Steve C. Orr, MCSD, MVP
    > http://Steve.Orr.net
    >
    >
    > "Diffident" <> wrote in message
    > news:...
    > > Hello All,
    > >
    > > I have a nested user control i.e., Control B which is loaded from Control
    > > A.
    > > Control A is itself dynamically loaded from a web form.
    > >
    > > Control A has a "Save" button which loads the Control B dynamically. Now
    > > in
    > > Control B there is a "Return" button which calls the method A of Control
    > > A.
    > > In method A, a session variable is being retrieved. My problem is whenever
    > > the control is passed back to the Control A, error is being thrown at the
    > > line where session is being retrieved.
    > >
    > > Can anyone please suggest me on how to go about this problem? Is there any
    > > other way to access session from user controls?
    > >
    > > Thanks for your pointers!!!
    > >

    >
    >
    >
     
    =?Utf-8?B?RGlmZmlkZW50?=, Nov 30, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Boban Dragojlovic
    Replies:
    2
    Views:
    516
    Patrice
    Apr 19, 2004
  2. =?Utf-8?B?RGlmZmlkZW50?=

    Retrieving session in a user control

    =?Utf-8?B?RGlmZmlkZW50?=, Nov 30, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    385
    =?Utf-8?B?RGlmZmlkZW50?=
    Nov 30, 2004
  3. =?Utf-8?B?V2ViTWF0cml4?=

    Retrieving data entered by user from Repeater Control

    =?Utf-8?B?V2ViTWF0cml4?=, Dec 9, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    445
    John Saunders
    Dec 11, 2004
  4. Mad Scientist Jr
    Replies:
    0
    Views:
    679
    Mad Scientist Jr
    Mar 22, 2006
  5. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    583
    Jonathan Wood
    Feb 2, 2010
Loading...

Share This Page