自动填写asp.net c# [英] Auto filling in asp.net c#

查看:68
本文介绍了自动填写asp.net c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,因为我正在做记住我的标准..但是值不是自动填写文本框中的任何建议.......感谢帮助

i have an application for in that i am doing the criteria of remember me.. But the value is not auto filling in text box any suggestions.......Thanks For Help

推荐答案

基本上提醒功能将在登录页面中实现以保存用户详细信息。这可以在cookie的帮助下实现。 cookies将存储在浏览器中。



Asp.net提供登录控件,并在下次内置选项时提醒我。这里的任何方式都是自定义代码,以便下次提醒我。



Basically remind functionality will be implement in login page to save the user details. this can be implemented with the help of cookies. cookies will store in browser.

Asp.net is providing login controls along with remind me next time in built in option. any way here is the custom code for remind me next time.

if (chkRememberPassword.Checked == true) 
{ 
Response.Cookies["UName"].Value = txtUName.Text; 
Response.Cookies["PWD"].Value = txtPWD.Text; 
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(2); 
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(2); 
} 
else 
{ 
Response.Cookies["UName"].Expires = DateTime.Now.AddMonths(-1); 
Response.Cookies["PWD"].Expires = DateTime.Now.AddMonths(-1); 
} 





在页面加载中粘贴以下代码片段





Paste the following code snippet in page load

if (!IsPostBack) 
{ 
if (Request.Cookies["UName"] != null) 
txtUName.Text= Request.Cookies["UName"].Value; 
if (Request.Cookies["PWD"] != null) 
txtPWD.Text.Attributes.Add("value", Request.Cookies["PWD"].Value); 
if (Request.Cookies["UName"] != null && Request.Cookies["PWD"] != null) 
chkRememberPassword.Checked = true; 
} 


根据您的要求,以下代码可以帮助您确定。



1st of all在验证码后面的Login Button中写下以下代码:

As per your requirement the following code will help you for sure.

1st of all Write the following Code inside the Login Button after your validation code:
protected void Button1_Click(object sender, EventArgs e)
    {
        HttpCookie  obj=new HttpCookie("Identity");
        obj.Values["UName"]=tbUser.Text;
        obj.Values["Pwd"]=tbPwd.Text;
        Response.Cookies.Add(obj);
        if (cbRemember.Checked)
            obj.Expires = DateTime.Now.AddMonths(3);
        else
            obj.Expires = DateTime.Now.AddMonths(-1);
    }



现在在Page_Load事件中写下以下代码:


Now write the following code inside Page_Load event:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.Cookies["Identity"] != null)
            {
                tbUser.Text = Request.Cookies["Identity"]["UName"].ToString();
                tbPwd.Attributes.Add("value", Request.Cookies["Identity"]["Pwd"].ToString());
                cbRemember.Checked = true;
            }
        }
    }



我已经在我的系统&它工作正常。

使用它&如果获得结果,则接受为解决方案。


I''ve tested this code in my System & It''s working fine.
Use it & Accept as Solution if get your Result.


这篇关于自动填写asp.net c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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