Newbie Cookie Question - Cookie Not Saved

  • Thread starter Thread starter Johnnie Norsworthy
  • Start date Start date
J

Johnnie Norsworthy

I have a cookie that I create when a user clicks a button on my web page:

HttpCookie Sig = new HttpCookie("Signature");
Sig.Value = Signature.Text; // a memo box
TimeSpan NinetyDays = new TimeSpan(90,0,0,0,0);
Sig.Expires = DateTime.Now+NinetyDays;
Response.Cookies.Add(Sig);

Tracing through this code shows no errors. But I must be missing something
else having to do with saving the cookie, because in my Page_Load I do this:

if (IsPostBack) return;
// get any signature that might exist
try
{
Signature.Text = Request.Cookies["Signature"].Value;
}
catch
{
Signature.Text = ""; //<< - always comes here with "Object reference not
set to an instance of an object"
}

This is such a simple routine, I hope someone can tell me what I am doing
wrong, or not doing.

Thanks for any help.

-Johnnie
 
Johnnie Norsworthy said:
I have a cookie that I create when a user clicks a button on my web page:

do you have a

Protected TextBox Signature;

and the id Signature still exists in the HTML?
HttpCookie Sig = new HttpCookie("Signature");
Sig.Value = Signature.Text; // a memo box
TimeSpan NinetyDays = new TimeSpan(90,0,0,0,0);
Sig.Expires = DateTime.Now+NinetyDays;
Response.Cookies.Add(Sig);

Tracing through this code shows no errors. But I must be missing
something
else having to do with saving the cookie, because in my Page_Load I do
this:

if (IsPostBack) return;
// get any signature that might exist
try
{
Signature.Text = Request.Cookies["Signature"].Value;
}
catch
{
Signature.Text = ""; //<< - always comes here with "Object reference not
set to an instance of an object"
}

This is such a simple routine, I hope someone can tell me what I am doing
wrong, or not doing.

Thanks for any help.

-Johnnie
 
Egbert Nierop (MVP for IIS) said:
do you have a

Protected TextBox Signature;

and the id Signature still exists in the HTML?

Yes, I do have (similar, but using DevExpress controls):
protected DevExpress.Web.ASPxDataControls.ASPxMemoEditor Signature;

and viewing the HTML:

ASPxMemoEditor id="Signature" runat="server" Font-Size="10pt"
Font-Names="Tahoma,Arial" Height="58px" Width="280px" BorderColor="Black">

-Johnnie

HttpCookie Sig = new HttpCookie("Signature");
Sig.Value = Signature.Text; // a memo box
TimeSpan NinetyDays = new TimeSpan(90,0,0,0,0);
Sig.Expires = DateTime.Now+NinetyDays;
Response.Cookies.Add(Sig);

Tracing through this code shows no errors. But I must be missing
something
else having to do with saving the cookie, because in my Page_Load I do
this:

if (IsPostBack) return;
// get any signature that might exist
try
{
Signature.Text = Request.Cookies["Signature"].Value;
}
catch
{
Signature.Text = ""; //<< - always comes here with "Object reference not
set to an instance of an object"
}

This is such a simple routine, I hope someone can tell me what I am doing
wrong, or not doing.
 
Johnnie Norsworthy said:
Yes, I do have (similar, but using DevExpress controls):
protected DevExpress.Web.ASPxDataControls.ASPxMemoEditor Signature;

and viewing the HTML:

ASPxMemoEditor id="Signature" runat="server" Font-Size="10pt"
Font-Names="Tahoma,Arial" Height="58px" Width="280px" BorderColor="Black">

Does anyone else have any idea why my web page's cookie is not saved
considering the information I provided in this thread?

This code traces fine with no error:

HttpCookie Sig = new HttpCookie("Signature");
Sig.Value = Signature.Text; // a memo box
TimeSpan NinetyDays = new TimeSpan(90,0,0,0,0);
Sig.Expires = DateTime.Now+NinetyDays;
Response.Cookies.Add(Sig);

but my Page_Load code never can get the cookie:

if (IsPostBack) return;
// get any signature that might exist
try
{
Signature.Text = Request.Cookies["Signature"].Value;
}
catch
{
Signature.Text = ""; //<< - always comes here with "Object reference not
set to an instance of an object"
}

Thanks for any help. I have had more problems with this cookie than
anything I do with ASP.NET and ADO.NET.

-Johnnie
 
Back
Top