如何使用c#将一个页面的文本框值放入asp.net中的另一个页面 [英] how to get the textbox value of one page in to another page in asp.net using c#

查看:75
本文介绍了如何使用c#将一个页面的文本框值放入asp.net中的另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

第一页如下



用户名文本框1

密码文本框2



第二页如下



用户文本框3





i想要用户在textbox1(在第一页中)输入用户名,该值将显示在textbox3中(在第二页中)。



我该如何在asp.net中执行使用c#。



问候,

narasiman)

解决方案

参考:

http://www.nullskull.com/a/10400710/eight-different-ways-to-transfer-data-from-one-page-to-another-page.aspx [<一个href =http://www.nullskull.com/a/10400710/eight-different-ways-to-transfer-data-from-one-page-to-another-page.aspx\"target =_ blanktitle = 新窗口> ^ ]


您可以使用Asp.Net Session来执行此操作是。请查看以下代码段:



在第一页的代码中,将此代码添加到按钮点击事件中:



 受保护  void  Button1_Click( object  sender,EventArgs e)
{
Session [ UserName] = textbox1.Text;
}





在第二页后面的代码中添加以下代码:



 受保护  void  Page_Load( object  sender,EventArgs e)
{
textbox3.Text = Session [ UserName] as String ;
}





希望有所帮助:)






如果您从第一页重定向到第二页,您可以使用QuesryString来维持状态。



响应。

重定向(SecondPage.aspx?UserName =+ txtUserName.text); 





在第二页获取值为下面



 textbox3.Text = Request.QueryString [UserName]; 









如果您想维护或访问多个用户名,请使用以下会话状态



会话[UserName] = txtUsername.Text; 





获取会话值



 textbox3.Text = Session [UserName]。toString(); 


First Page as follows

User Name textbox1
Password textbox2

Second Page as follows

User textbox3


i want user enters the User Name in textbox1 (in First Page) that value to be shown in textbox3 (in Second Page).

for that how can i do in asp.net using c#.

Regards,
narasiman )

解决方案

Refer:
http://www.nullskull.com/a/10400710/eight-different-ways-to-transfer-data-from-one-page-to-another-page.aspx[^]


You can use Asp.Net Session to do this. Check out the following code snippet:

In the code behind of the first page, add this code to your button click event:

protected void Button1_Click(object sender, EventArgs e)
        {
            Session["UserName"] = textbox1.Text;
        }



In the code behind of the second page add this code:

protected void Page_Load(object sender, EventArgs e)
        {
            textbox3.Text = Session["UserName"] as String;
        }



Hope it helps :)


Hi,

If you are redirecting from first page to second page you can use QuesryString to maintain the state.

Response.

Redirect("SecondPage.aspx?UserName="+txtUserName.text);



Get values in second page as below

textbox3.Text = Request.QueryString["UserName"];



OR

If you want to maintain or access the username more than one page use session state as below

Session["UserName"] = txtUsername.Text;



Get session value

textbox3.Text = Session["UserName"].toString();


这篇关于如何使用c#将一个页面的文本框值放入asp.net中的另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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