回到与值previous页面仍然美元的文本框中p $ psent [英] back to the previous page with values still present in textboxes

查看:95
本文介绍了回到与值previous页面仍然美元的文本框中p $ psent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

确定..我有一个起始页面文本框我发送的文本框上的下一个按钮点击使用缓存另一个页面输入的值。

现在我有一个问题,就是当用户进入到下一个页面的广告决定再回去,他应该能够做到这一点,他在文本框中输入的值应该还是present。

有没有办法这样做...

我的code发送的值是:


  

块引用


保护无效Button4_Click(对象发件人,EventArgs五)

  {        如果(TextBox2.Text ==|| TextBox3.Text ==)        {            Label1.Text =(*请确保输入的所有字段);            Label1.Visible = TRUE;        }        其他        {            缓存[PolicyName] = TextBox2.Text;            缓存[PolicyDesc] = TextBox3.Text;           的Response.Redirect(〜/ Addnewpolicy3.aspx);        }    }

和我收到这下一个页面上

保护无效的Page_Load(对象发件人,EventArgs五)

  {        如果(!的IsPostBack)        {            串PN =缓存[PolicyName]的ToString()。            字符串PD =缓存[PolicyDesc]的ToString()。            串OS =缓存[OperatingSystem的]的ToString()。
        }
    }


  

块引用



解决方案

缓存由所有用户共享。上面的code会导致用户之间被共享的信息。如果您希望每个用户的临时存储,你应该使用Session来代替。除此之外,我可以让2建议:


  1. 与会话继续,你的做法是细

  2. 看那向导控制 http://msdn.microsoft.com/en -us /杂志/ cc163894.aspx

为了使值恢复,在控制简单的做到这一点:

 < ASP:文本框ID =改为txtName=服务器文本='<%=会话[名称]%>'>< / ASP :文本框>

ok.. i have a start page with textboxes i am sending the values entered in the textbox to another page using Cache on click of a next button.

Now i have a problem that when the user goes to the next page ad decides to go back again he should be able to do so and the values he entered in the textboxes should still be present.

is there a way to do so...

my code for sending values is:

Blockquote

protected void Button4_Click(object sender, EventArgs e)

    {

        if (TextBox2.Text == "" || TextBox3.Text == "")

        {

            Label1.Text = ("*Please ensure all fields are entered");

            Label1.Visible = true;

        }

        else

        {

            Cache["PolicyName"] = TextBox2.Text;

            Cache["PolicyDesc"] = TextBox3.Text;

           Response.Redirect("~/Addnewpolicy3.aspx");

        }

    }

and i receive this by on the next page as

protected void Page_Load(object sender, EventArgs e)

    {

        if (!IsPostBack)

        {

            string pn = Cache["PolicyName"].ToString();

            string pd = Cache["PolicyDesc"].ToString();

            string os = Cache["OperatingSystem"].ToString();


        }
    }

Blockquote

解决方案

Cache is shared by all users. The code above will result in information being shared between users. If you want per-user temp storage you should use the Session instead. Other than that I can make 2 recommendations:

  1. Proceed with Session, your approach is fine
  2. Look at the Wizard control http://msdn.microsoft.com/en-us/magazine/cc163894.aspx

To make the values restore, in the controls simple do this:

<asp:TextBox ID="txtName" runat="server" text='<%=Session["Name"] %>'></asp:TextBox>

这篇关于回到与值previous页面仍然美元的文本框中p $ psent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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