943,154 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 954
  • ASP.NET RSS
Feb 9th, 2010
0

C#/Commented code running

Expand Post »
I have a few C# questions too, but this is mainly an ASP problem I think. All the code I mention below takes place in the code-behind of my Master Page. I worry a lack of knowledge on master pages may be the problem too. Excuse the database name; my dad wants to make a site called 'Dumbassery.com' which is what I'm working on :P...

I've been working on an ASP.NET site with C# code-behind. I wanted to add some cookies for login stuff but the cookies weren't sticking around. I decided, "Fix it later, try to work around it for now." I commented out the code, rebuilt, and the code continued to run. I know this because I have 2 panels that switch visibility on correctly logging in. I've closed Visual Studio, I've taken out the code completely and rebuilt, and the code continues to run!!

Master Page C# code-behind (with the commented out sections):
c# Syntax (Toggle Plain Text)
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. if (!IsPostBack)
  4. {
  5. //sets banner and background according to current site properties
  6. CurrentSiteProperty cs = (from c in new DumbasseryDatabaseDataContext().CurrentSiteProperties where c.id == 1 select c).First();
  7. BannerImage.ImageUrl = cs.Banner.fileLocation;
  8. bodyTag.Style.Add(HtmlTextWriterStyle.BackgroundImage, cs.BackgroundImage.fileLocation);
  9. }
  10. /*if (Request.Cookies["loggedIn"] != null && Request.Cookies["loggedIn"].Value == "true")
  11.   {
  12.   LoginPanel.Visible = false;
  13.   LoggedInPanel.Visible = true;
  14.   LoggedInHomeLink.Text = Request.Cookies["loggedIn"].Values.Get("userName") + " Home";// Request.Cookies["loggedIn"]["userName"] + " Home";
  15.   Response.Cookies["loggedIn"].Expires = DateTime.Now.AddDays(1);
  16.   }*/
  17. }
  18.  
  19. protected void Login(Object o, EventArgs e)
  20. {
  21. /*User loginUser = (from u in new DumbasseryDatabaseDataContext().Users where u._password == PasswordTextBox.Text && u.loginName == LoginNameTextBox.Text select u).FirstOrDefault();
  22.   if (loginUser != null)
  23.   {
  24.   LoginPanel.Visible = false;
  25.   LoggedInPanel.Visible = true;
  26.   LoggedInHomeLink.Text = loginUser.displayName + " Home";
  27.   HttpCookie loggedIn = new HttpCookie("loggedIn");
  28.   loggedIn.Values.Add("userName", loginUser.displayName);
  29.   loggedIn.Value = "true";
  30.   loggedIn.Expires = DateTime.Now.AddDays(1);
  31.   Response.Cookies.Add(loggedIn);
  32.   }*/
  33. }
  34.  
  35. protected void Logout(Object o, EventArgs e)
  36. {
  37. /*Response.Cookies["loggedIn"].Expires = DateTime.Now;
  38.   LoginPanel.Visible = true;
  39.   LoggedInPanel.Visible = false;*/
  40. }

A couple other issues I've had that may or may not be tied to the problem that need fixing regardless:
I mention two controls in my Page_Load above (BannerImage and bodyTag) that give the error "The name 'controlName' does not exist in the current context." Even though they're showing as errors after building, the site still runs. It's not a problem as much as it is extremely confusing why this is happening (not being able to intellisense the controls doesn't help either).

The other issue is the cookies I mentioned before. The cookie code I was playing with is the C# code commented out above. Any help on why they aren't sticking around would be extremely helpful. I could tell something was wrong with my cookies because the controls they alter (the previously mentioned panels) appear at the top of the master page as follows:

Before Logging In:
Note that the LoginPanel is visible, LoggedInPanel is not, and the HyperLink has no text.
asp.net Syntax (Toggle Plain Text)
  1. <asp:Panel runat="server" ID="LoginPanel">
  2. more controls
  3. </asp:Panel>
  4. <asp:Panel runat="server" ID="LoggedInPanel" Visible="false" >
  5. <asp:HyperLink ID="LoggedInHomeLink" runat="server" NavigateUrl="~/Register.aspx" />
  6. more controls
  7. </asp:Panel>

After Logging in:
Note that the LoginPanel and LoggedInPanel successfullly change visibility and the Hyperlink text is now "username Home".
asp.net Syntax (Toggle Plain Text)
  1. <asp:Panel runat="server" ID="LoginPanel" Visible="false">
  2. more controls
  3. </asp:Panel>
  4. <asp:Panel runat="server" ID="LoggedInPanel" Visible="true" >
  5. <asp:HyperLink ID="LoggedInHomeLink" runat="server" NavigateUrl="~/Register.aspx" Text="username Home" />
  6. more controls
  7. </asp:Panel>

The very next page visited after the initial login redirection:
Note that the visibilities remained the same, but the Hyperlink text has lost the username.
asp.net Syntax (Toggle Plain Text)
  1. <asp:Panel runat="server" ID="LoginPanel" Visible="false">
  2. more controls
  3. </asp:Panel>
  4. <asp:Panel runat="server" ID="LoggedInPanel" Visible="true" >
  5. <asp:HyperLink ID="LoggedInHomeLink" runat="server" NavigateUrl="~/Register.aspx" Text=" Home" />
  6. more controls
  7. </asp:Panel>

The 2nd page visited after the initial login redirection:
The page returns to how it was before login.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
tuckerblue is offline Offline
1 posts
since Feb 2010

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: Gridview will not update using sqldata source
Next Thread in ASP.NET Forum Timeline: How to capture insert/delete in dropdownlist with multi datasources





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC