会话价值不会显示 [英] Session Value wont show up

查看:69
本文介绍了会话价值不会显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在文本框中显示会话值时遇到问题.

这是我的代码:

在我的页面加载中:

Hello guys,

I have problem about displaying Session value in textbox.

Here is my code:

Inside my page load:

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");
}



和我的MessageBox代码:



and my code for MessageBox:

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




这让我发疯,因为我有两个显示为Test1和Test2的警报框,但是其中一个我想显示的警报框却没有出现.

我已经仔细检查了Session是否不为null,并且该值已分配给msgBoxVal,并且在调试模式下它不会引发异常.有人可以告诉我我哪里错了吗?

谢谢.




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.

推荐答案

您好尝试了您的代码并更改了一些简单的小东西,然后我测试了结果
试试这个
hi tried your code and changed simple small things and i tested the results
try this
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>"));
   }




您可能会看到以下链接:
命令字段中的会话值

并为您的消息框:

msgbox不会显示确定"按钮


请别忘了投票,如果有帮助的话,其他人可以考虑作为答案 ...

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,


这是冗长的编码.您可以直接访问javascript中的 Session
看到这个

This is the lengthy coding. either you directly access Session in javascript
see this

var Labeldet;
Labeldet = = <%=Session("LabelDetails")%>;


这篇关于会话价值不会显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆