Click here to Skip to main content
12,945,800 members (51,861 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
 
public partial class Change_Password : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
 

    public string UsrID
    { get; set; }
 

 
    private void ShowResult(string _msg)
    {
        divmsg2.Visible = true;
        ltrmsg2.Text = _msg;
    }
 

    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        try
        {
 

            if (String.IsNullOrEmpty(TxtOldPass.Text) || String.IsNullOrEmpty(TxtNewPass.Text) || String.IsNullOrEmpty(TxtConfPass.Text))
            {
                ShowResult("Please fill in the fields");
            }
 
            else
            {
 
                if (Context.User.Identity.IsAuthenticated)
                {
 
                    usermasterDataContext context = new usermasterDataContext();
                    var data = context.passwords.Single(m => m.UsrPassword == TxtOldPass.Text);
                    var UID = context.passwords.Where(i => i.UsrPassword==TxtOldPass.Text).Select(i => i.ID).ToList();
                   
                    foreach (int i in UID)
                    {
                        UsrID = i.ToString();
                    }
                    string oldpass = data.UsrPassword.ToString();
                    string newpass = TxtNewPass.Text;
                    string confpass = TxtConfPass.Text;
 
                    if (oldpass == TxtOldPass.Text)
                    {
                        var data2 = (from p in context.passwords
                                     where p.ID == Convert.ToInt64(UsrID)
                                     select p).Single();
 
                        data2.UsrPassword = newpass.ToString();
                        context.SubmitChanges();
                     
                        ShowResult("Password Changed Successfully");
                        //Panel1.Visible = false;
                       
                    }
                    else
                    {
                        ShowResult("Old password does not match");
                        return;
                    }
                    if (TxtConfPass.Text != TxtNewPass.Text)
                    {
                        ShowResult("New Password and Confirm Password do not match");
                        return;
                    }
                }
 
            }
        }
 
        catch
        {
            ShowResult("Some error occured. Please try again later!");
        }
 
        finally
        {
            TxtOldPass.Text = "";
            TxtNewPass.Text = "";
            TxtConfPass.Text = "";
        }
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Panel1.Visible = false;
        LinkButton lb = (LinkButton)this.Parent.FindControl("lnkChangepwd");
        lb.Visible = true;
    }
}
Posted 14-Jan-13 21:37pm
Updated 14-Jan-13 21:38pm
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

why are you confusing yourself. why dont you use simple code, use this algo:
on your button click

select and password from table where user name=logged in user
if (pasword.text=="" || confermpass =="")
{
enter pass
}
else
{
upadate password where user name=logged in user
}
i hope it will be very easy for you :)
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,899
CHill60 3,180
Maciej Los 2,453
Jochen Arndt 1,910
ppolymorphe 1,785


Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 15 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100