Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

I have problem about displaying Session value in textbox.

Here is my code:

Inside my page load:

C#
string msgBoxVal = string.Empty;
if (Session["LabelDetails"] != null)
{
  msgBoxVal = (String)Session["LabelDetails"];
  Session.Remove("LabelDetails");
}
if (msgBoxVal != "")
{
  MessageBox("Test1");
  MessageBox("The shipping label is successfully deleted! Deleted label details: " + msgBoxVal);
  MessageBox("Test2");
}


and my code for MessageBox:
C#
private void MessageBox(string msg)
{
  Page.Controls.Add(new LiteralControl("<script language='javascript'> window.alert('" + msg.Replace("'", "\\'") + "')</script>"));
}



This drives me crazy because I am having two alertbox show as Test1 and Test2 but one which is in the middle that I want to show won't appear.

I have double checked that Session is not null and the value gets assigned to msgBoxVal and during the debug mode it doesnt throw an exception. Can someone tell me where I am wrong?

Thanks.
Posted

hi tried your code and changed simple small things and i tested the results
try this
C#
protected void Page_Load(object sender, EventArgs e)
   {
       //the line was just to test it
      //Session.Add("LabelDetails", 454);
       string msgBoxVal = string.Empty;
       if (Session["LabelDetails"] != null)
       {
           msgBoxVal = Convert.ToString(Session["LabelDetails"]);
           Session.Remove("LabelDetails");
       }
       if (msgBoxVal != "")
       {
           MessageBox("Test1");
           MessageBox("The shipping label is successfully deleted! Deleted label details: " + msgBoxVal);
           MessageBox("Test2");
       }


   }

   private void MessageBox(string msg)
   {
       Page.Controls.Add(new LiteralControl("<script type=\"text/javascript\"> window.alert('" + msg.Replace("'", "\\'") + "')</script>"));
   }
 
Share this answer
 
Comments
wonder-FOOL 16-Dec-11 11:17am    
Sara thank you for your answer but still it didnt display the message box that I want :(
Hi,

You may see these links:
session value in command field

and for your messagebox:

msgbox to NOT display OK Button


Please do not forget to vote if could help so that others may consider as an answer...

Regards,
 
Share this answer
 
Comments
wonder-FOOL 15-Dec-11 22:57pm    
Thank you for your answer but your 2 links doesnt address my issue and they are not helping me. In first one basically says that beware of the session expiration. Since I indicated in my question that I have retrieved the value and can see it this means that session havent expired yet. for your second link I have no idea how you come up with msgbox to not display ok button? i didnt ask such a thing like that :) and seems like the link is broken.
Al Moje 16-Dec-11 1:03am    
Hi, I am not saying that you have no idea to come up with msgbox. My allegation is that maybe in your msgbox had triggers such an error…
Sorry for the broken link… The url is at :
http://www.codeproject.com/Answers/299619/window-close-is-not-working#answer1

Yuo may try this...
wonder-FOOL 16-Dec-11 11:33am    
Thank you. I have checked the link and tried it. I worked :) Also , the funny thing is, I have also asked the question on the link that you provided lol.
This is the lengthy coding. either you directly access Session in javascript
see this

JavaScript
var Labeldet;
Labeldet = = <%=Session("LabelDetails")%>;
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900