ASP.NET(C#)中的文本框问题 [英] Textbox problem in asp.net(c#)

查看:77
本文介绍了ASP.NET(C#)中的文本框问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录页面...它包含两个文本框... txtusername和txtpassword ...当我单击文本框上的Enter按钮,然后将其重定向到主页...母版页有一个表单标签.但是登录页面上没有表单标签....请帮助我...我认为表单标签有问题....

解决方案

如果要发布值这两个文本框中,然后从后面的代码中分别使用txtusername.Text和txtpassword.Text获取它们的值.

如果要在click事件上重定向到另一个页面,则要使用该页面上的值,首先需要将它们存储在诸如Session之类的位置.这是一个简单的示例:

按钮的click事件中的代码以将值存储在会话中:

会话[" ] = txtusername.Text;
会话[" ] = txtpassword.Text; 



用于从另一页上的会话获取值的代码:

 string username =(string)(Session ["username"] ??");
字符串密码=(字符串)(会话[密码"] ??"); 



此处是会话的很好参考:在ASP.NET中浏览会话 [ ^ ]


我解决了它....主页包含表单标签runat ="server" ...但是在登录页面中没有表单标签...因此我删除了主页表单标签并替换为登录页面.... tat的bcoz,只有当我单击文本框时才能转到主页....


Hi i have a login page...it contain two textbox...txtusername and txtpassword...when i click on enter button on textbox then it redirect to home page...master page have a form tag..but login page dont have form tag....please help me...i think some problem form tag....

解决方案

If you are posting the values of those two text boxes, then from the code behind you can get the values of them by using txtusername.Text and txtpassword.Text respectively.

If you are redirecting to another page on the click event, then to use the values on that page you will first need to store them somewhere such as the Session. Here''s a simple example:

Code in the button''s click event to store values in the session:

Session["username"] = txtusername.Text;
Session["password"] = txtpassword.Text;



Code used to get the values from the session on another page:

string username = (string)(Session["username"] ?? "");
string password = (string)(Session["password"] ?? "");



Here''s a good reference for sessions: Exploring Session in ASP.NET[^]


hi i solved it....master page contain form tag runat="server"...but in login page no form tag...so i delete master page form tag and replace it on login page....bcoz of tat only when i click on textbox it going to the home page....


这篇关于ASP.NET(C#)中的文本框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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