如何在页面加载中将数据持久保存在TextBox中 [英] How to persist the data in TextBox in page Loads

查看:82
本文介绍了如何在页面加载中将数据持久保存在TextBox中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

Hi All

protected void btnPreview_Click(object sender, EventArgs e)
    {

        ArrayList array = new ArrayList();

        array.Add(txtAD.Text);
        array.Add(txtASO.Text);
        array.Add(txtController.Text);
        array.Add(txtGPS.Text);
        array.Add(txtTAP.Text);

        Session["ArrayList"] = array;
        ViewState["ArrayList"] = array;
        Response.Redirect("~/Preview.aspx");


}
到现在为止都很好

在预览"页面中,我有一个编辑"按钮.通过单击我将再次将我的页面重定向到上一页..那里的文本框值不存在..
我想在不同页面加载之间保留文本框值..

我知道我应该使用视图状态.但是无法实现它们.
请帮助我.

谢谢


}
till now it fine

In the Preview page i have a Edit Button. by cliking on i will redirected my page again to the Previous page.. there the text box values are not there..
i want to persist the textbox values between different page loads..

I know that i shoiuld use view state.. but could''t able to implement them.
Please help me in that.

Thanks

推荐答案

您不应该使用ViewState,因为要在不同的页面之间导航.改为使用会话.
You shouldn''t use ViewState because you''re navigating between different pages. Use Session instead.


http://msdn.microsoft.com /en-us/library/ms750637.aspx [ ^ ]或Edit按钮上的<input type="button" value="Back to Previous Page" onClick="javascript: history.go(-1)">对您有所帮助.
http://msdn.microsoft.com/en-us/library/ms750637.aspx[^] or <input type="button" value="Back to Previous Page" onClick="javascript: history.go(-1)"> on Edit button will be helpful to you.


我同意Jim

以这种方式尝试

i agree with Jim

try in this way

On Click Of btnPreview
session["Name"]=Convert.tostring(txt.text);

Redirect to nextPage 

//do your work 

Redirect to previous Page 

//in the Page Load Check 

if(session["Name"]!=null)
TextBox1.text = Session["Name"];
//clear that Session 

Session["Name"]=null;
Session.clear(); 


这篇关于如何在页面加载中将数据持久保存在TextBox中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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