Showing posts with label write. Show all posts
Showing posts with label write. Show all posts

Saturday, March 24, 2012

Trouble viewing ASP buttons on a web form

Hi,

I am a long-time java programmer, trying to learn about ASP.NET. I am trying write a simple "Hello, Browser" web form using the Visual Studio .NET web form designer. The form consists of a web form label and 3 web form buttons. The buttons don't perform any function. However, when I build and run the program, a browser pops up, but only displays the label and not the buttons. Can anyone tell me what the problem might be? Is it a problem with the code, or maybe some settings?

Thank YouCan you post your code?
If you installed IIS after Visual Studio .NET, you have to register ASP.NET with IIS. You can do this by opening a VS.NET command prompt (i.e. Start > Programs > Visual Studio .NET > Tools > Command Prompt) and typing:

aspnet_regiis -i

That should do the trick. ;)
Super!

This forum is such an amazing resource. I would have never guessed that on my own. Stanley Tan, your solution worked.

Thank you. Thank You. Thank You.

Trouble with changing a value in a cookie.

I wanted to change a value in a existing cookie. I read the old value, modify it and to write the new value in the old cookie. Here is the code:

public bool SetCookie(string cookiename, string cookievalue, int iDaysToExpire) //create the cookie
{
try
{
HttpCookie objCookie = new HttpCookie(cookiename);
Response.Cookies.Clear();
Response.Cookies.Add(objCookie);
objCookie.Values.Add(cookiename, cookievalue); // adding the value to the cookie
DateTime dtExpiry = DateTime.Now.AddDays(iDaysToExpire); //expires
Response.Cookies[cookiename].Expires = dtExpiry;
}
catch (Exception e)
{
return false;
}
return true;
}

public string GetCookie(string cookiename)// method which gives the value from the cookie
{
string cookyval = "";
try
{
cookyval = Request.Cookies[cookiename].Value;
}
catch (Exception e)
{
cookyval = "";
}
return cookyval;
}

protected void Page_Load(object sender, EventArgs e)
{

String t, s,t1;
int i = 0;
s = "";
t = "";

t = GetCookie("test");//reading the cookie
//removing the name and getting the value
try
{
lbl1.Text = t; //
t1 = t.Remove(0, 9);
i = Int32.Parse(t1);
i = i + 1; //the value is modified
}
catch (Exception w) { lbl3.Text = "Convert isnt working."; }
s = Convert.ToString(i);

//writing the new value in the cookie
SetCookie("test", s, 1);

//testing to see if the new value is written
t1 = GetCookie("test");
lbl2.Text = s;
lbl3.Text = t1;
}
}What is your question, exactly? This code re-sets the cookie each time it runs. It seems to return exactly what you're setting it to ("test=0"). (Is that the value that you want it to have?)

Tuesday, March 13, 2012

Troubles with cookies

Hi,

I've some troubles using cookies in my ASP.NET application (C#).
I write a cookie in a page which is in the /login subfolder of the web and I
set an appropriate expire date. But if I intend to read that cookie from
other pages which lie directly at the root folder of the web app, I only get
an empty value and the expire date "1/1/1". What is wrong? Can't I read all
cookies of the web no matter where they were set? Can anyone help me?

AzatUsually when you issue a cookie, it's available site-wide. The Path property
indicates what level in the app the cookie belongs to and it defaults to
"/", which means the cookie is available site wide.

I'm wondering if either the client has disabled cookies or if the time on
the client machine is out of synch with the server.

-Brock
DevelopMentor
http://staff.develop.com/ballen

> Hi,
> I've some troubles using cookies in my ASP.NET application (C#).
> I write a cookie in a page which is in the /login subfolder of the web
> and I
> set an appropriate expire date. But if I intend to read that cookie
> from
> other pages which lie directly at the root folder of the web app, I
> only get
> an empty value and the expire date "1/1/1". What is wrong? Can't I
> read all
> cookies of the web no matter where they were set? Can anyone help me?
> Azat