C# .NET - Session message error
Asked By Elvin
09-Feb-12 05:48 PM

I am trying to create two Session messages through textboxes where it will display the two messages in two different locations in the website inside the Master Page.
The good side: It works and the messages displays in both sections of the webpage.
The bad side is that when I try to clear this message to add a different message on one, it deletes the other message.
Can anyone provide information regarding how to have just delete one message and not the other?
My code is as follows for the Admin Page:
<br />
For Current News Section side tab message displayed in Web Pages
<hr />
<asp:TextBox ID="txtMessage" runat="server" Height="53px" TextMode="MultiLine"
Width="277px"></asp:TextBox>
<br />
<br />
<asp:Button ID="ControlInfo" runat="server" Text="Add Message" onclick="ControlInfo_Click" />
<br />
<asp:Button ID="btnClear" runat="server" onclick="btnClear_Click1"
Text="Clear Message" />
<br />
<hr />
For Other Information side tab Message displayed in Web Pages
<asp:TextBox ID="txtOtherInfo" runat="server" Height="53px" TextMode="MultiLine"
Width="277px"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnOtherInfo" runat="server" Text="Add Message" onclick="btnOtherInfo_Click" />
<br />
<asp:Button ID="btnClearOtherInfo" runat="server" onclick="btnClearOtherInfo_Click1"
Text="Clear Message" />
<br />
The code behind for the Admin.aspx.cs is as followed:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
//
using System.Configuration;
using System.Data;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Security;
using System.Web.UI.WebControls.WebParts;
//
namespace sP
{
public partial class libraryAdmin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void ControlInfo_Click(object sender, EventArgs e)
{
// Response.Redirect("About_Miramar_Library.aspx?Message=" + txtMessage.Text);
// Session Created
Session["Message"] = txtMessage.Text;
Response.Redirect("main_Home.aspx");
}
protected void btnClear_Click1(object sender, EventArgs e)
{
string message1 = txtMessage.Text;
if (txtMessage.Text == message1)
{
//Clearing the Session
Session.Clear();
Response.Redirect("main_Home.aspx");
}
/*
// Clearing the Session
if (Session["Message"] == txtMessage.Text )
{
Session.Clear();
Response.Redirect("main_Home.aspx");
// lblMessage.Text = " ";
} */
}
protected void btnOtherInfo_Click(object sender, EventArgs e)
{
//Session created
Session["OtherInfoMessage"] = txtOtherInfo.Text;
Response.Redirect("main_Home.aspx");
}
protected void btnClearOtherInfo_Click1(object sender, EventArgs e)
{
string message2 = txtOtherInfo.Text;
if (txtOtherInfo.Text == message2)
{
//Clearing the Session
Session.Clear();
Response.Redirect("main_Home.aspx");
}
/* if (Session["OtherInfoMessage"] == txtOtherInfo.Text)
{
//Clearing the Session
Session.Clear();
Response.Redirect("main_Home.aspx");
} */
}
}
}
The code behind for the MasterPageOne.Master is :
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="MasterOne.master.cs" Inherits="sP.MasterOne" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<link href="style/Demos.css" rel="stylesheet" type="text/css" />
<script src="Scripts/jquery-1.3.2.min.js" type="text/javascript"></script>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<link href="style/colour.css" rel="stylesheet" type="text/css" />
<asp:ContentPlaceHolder ID="head" runat="server">
</asp:ContentPlaceHolder>
</head>
<body>
<form id="form1" runat="server">
<div>
<div id="main">
<div id="links">
<!-- **** INSERT LINKS HERE **** -->
<!--<a href="#">another link</a> | <a href="#">another link</a> | <a href="#">another link</a> | <a href="#">another link</a> -->
</div>
<div id="logo"><h1></h1></div>
<div id="content">
<div id="menu">
<ul>
<li><a id="selected" href="main_Home.aspx">home</a></li>
<li><a href="About_Miramar_Library.aspx">about library</a></li>
<li><a href="About_ASC.aspx">about asc</a></li>
<li><a href="Contact_ASC.aspx">contact asc</a></li>
<li><a href="Contact_Library.aspx">contact library</a></li>
<li><a href="FAQ.aspx"> FAQ </a></li>
</ul>
</div>
<br />
<div id="column1">
<div class="sidebaritem">
<div class="sbihead">
<h1>latest news</h1>
</div>
<div class="sbicontent">
<!-- **** INSERT NEWS ITEMS HERE **** -->
<h2>2.8.2012</h2>
<p> <asp:Label ID="lblMessage" runat="server" Text=""></asp:Label></p>
<p><a href="#"></a></p>
<p></p>
<p></p>
</div>
</div>
<div class="sidebaritem">
<div class="sbihead">
<h1>additional links</h1>
</div>
<div class="sbilinks">
<!-- **** INSERT ADDITIONAL LINKS HERE **** -->
<ul>
<li><a href="http://readdevry.blogspot.com/">South Florida Reading Circles</a></li>
<li><a href="Picture.aspx">Picture Gallery</a></li>
<li><a href="ascVideos.aspx">ASC Tutoring Videos</a></li>
<li><a href="http://www.my.devry.edu">My DeVry</a></li>
</ul>
</div>
</div>
<div class="sidebaritem">
<div class="sbihead">
<h1>other information</h1>
</div>
<div class="sbicontent">
<!-- **** INSERT OTHER INFORMATION HERE **** -->
<p> <asp:Label ID="lblOtherInfo" runat="server" Text=""></asp:Label></p>
</div>
</div>
</div>
<div id = "column2" >
<asp:ContentPlaceHolder ID="ContentPlaceHolder1" runat="server">
</asp:ContentPlaceHolder>
</div>
</div>
<div id="footer">
copyright © 2011| add more content here</a>
</div>
</div>
</div>
</form>
</body>
</html>
-----------------------------------
The code behind for MasterOne.Master.cs is:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace sP
{
public partial class MasterOne : System.Web.UI.MasterPage
{
protected void Page_Load(object sender, EventArgs e)
{
/* if (Request.QueryString["Message"] != null)
lblMessage.Text = Request.QueryString["Message"];
*/
// The code below shows how to get the session value.
if (Session["Message"] != null)
lblMessage.Text = Session["Message"].ToString();
// The code below shows how to get the session value.
if (Session["OtherInfoMessage"] != null)
lblOtherInfo.Text = Session["OtherInfoMessage"].ToString();
}
}
}
---------------------------------
dipa ahuja replied to Elvin
To display the message you are using the = but you have to use the += so it will not replace the previous message
for ex
//first message
Label1.Text = "Message 1";
Label1.Text += "Message 2"

m trying to create a class with a member that will iterate through a web page and discover all the controls on the page, list their types, names and what value they hold. What I want is to be able to save all the fields on any page without having to know what fields there are to begin with. I'll then save create a class that can iterate through all the pages on the site calling the page class for each page so all the controls on the entire site can be saved and retrieved. This will bunch of sessions. I will also allow me to enable / disable controls site wide or page wide from anywhere on the site. When I attempt to 'discover' what controls are on a given page I have managed to determine the control types but not their names. Can anyone provide an example or point me to where I might find one? Thanks! .NET Framework Discussions ControlInfo (1) CheckBox (1) TextBox (1) LinkButton (1) EventArgs (1) Control (1) ITextControl (1) GetValue (1
type = "submit" value = "Enter" size = 30 OnServerClick = "SubmitBtn_Click" runat = "server" / > / / Tony C# Discussions HtmlInputText (1) Page (1) LiteralControl (1) ControlInfo (1) EventArgs (1) Relative (1) ASP.NET (1) TextBox (1) They so something relative different. Try run the following .aspx: public class ControlInfo { public string Clazz { get; set; } public string Name { get; set; } public string Text { get; set void Page_Load(Object sender, EventArgs e) { List<ControlInfo> lst = new List<ControlInfo> (); foreach(Control c in f.Controls) { if(c is LiteralControl) { lst.Add(new ControlInfo{Clazz = c.GetType().FullName, Name = "", Text = Server.HtmlEncode(((LiteralControl)c).Text)}); } else { lst.Add(new
frames navigation .NET Framework I'm using frames on my home page like this: frame frame frame frame frame frame frame page page frame page page frame page page frame page page frame page page frame page page frame page page frame page page How do
msg box public static void ShowAlertMessage( string error) { Page page = HttpContext .Current.Handler as Page ; if (page ! = null ) { error = error.Replace( "'" , " \ '" ); ScriptManager .RegisterStartupScript(page, page.GetType(), "err_msg" , "alert('" + error + "');" , true ); } } public static void ShowAlertMessage( string error) { Page page = HttpContext .Current.Handler as Page ; if (page ! = null ) { error = error.Replace( "'" , " \ '" ); ScriptManager .RegisterStartupScript(page, page