i update password but after that when i click on any other link it shows required fie

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jagdeep gupta
    New Member
    • Aug 2010
    • 98

    #1

    i update password but after that when i click on any other link it shows required fie

    I update password, but after that when i click on any other link it shows required fie...


    Code:
    <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="setting.aspx.cs" Inherits="setting" Title="Untitled Page" %>
    <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
    <asp:Panel ID="cppanel" runat="server" BorderWidth="2" BorderColor="DarkGray" BackColor="DarkGray" Width=100% Height="1px">
        <br />
        
    <asp:Label ID="cplable" runat="server" BackColor="DarkGray" Text="Change Password" Font-Bold="True" Font-Size="X-Large" Width="245px"></asp:Label></asp:Panel>
        <br />
        <br />
        <br />
        <asp:Panel ID="cpppassword" runat="server" Width="563px">
        <table align="center">
        <tr>
        <td style="width: 193px">
            &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        <asp:Label ID="cplodlpassword" runat="server" Text="Enter Old Password"></asp:Label>
        </td>
        <td style="width: 357px">
            <br />
        <asp:TextBox ID="cptoldpassword" runat="server" TextMode="Password"></asp:TextBox>
            <asp:RequiredFieldValidator ID="cprfvoldpassword" runat="server" ErrorMessage="Required*" ControlToValidate="cptoldpassword"></asp:RequiredFieldValidator>
            <br />
        </td>
        </tr>
        <tr>
        <td>
            &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
        
        <asp:Label ID="cplnewpassword" runat="server" Text="Enter New Password"></asp:Label></td>
     <td style="width: 357px">
         <br />
        <asp:TextBox ID="cptnewpassword" runat="server" TextMode="Password"></asp:TextBox><asp:RequiredFieldValidator ID="cprfvnewpassword" runat="server" ErrorMessage="Required*" ControlToValidate="cptnewpassword"></asp:RequiredFieldValidator><br />
     </td>
     </tr>
     <tr>
     <td>
         &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
     <asp:Label ID="cplconfirmpassword" runat="server" Text="Confirm Password"></asp:Label>
     </td>
     <td style="width: 357px">
         <br />
     <asp:TextBox ID="cptconfirmpassword" runat="server" TextMode="Password" ></asp:TextBox>
     <asp:RequiredFieldValidator ID="cprfvconfirmpassword" runat="server" ErrorMessage="Required*" ControlToValidate="cptconfirmpassword" Display="Dynamic"></asp:RequiredFieldValidator>
         <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Not Match*" Display="Dynamic" ControlToCompare="cptnewpassword" ControlToValidate="cptconfirmpassword"></asp:CompareValidator>
         <br />
     </td>
     
     </tr>
     <tr>
     <td colspan="2">
         &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
         &nbsp; &nbsp; &nbsp;&nbsp;
     <asp:Button ID="cpbchangepassword" runat="server" Text="Change Password" OnClick="cpbchangepassword_Click" />
     </td>
     </tr>
     </table>
        </asp:Panel>
        
    </asp:Content>
    Last edited by Frinavale; Sep 7 '10, 03:58 PM. Reason: Added the question to the thread.
  • mzmishra
    Recognized Expert Contributor
    • Aug 2007
    • 390

    #2
    check if you have set cause validation=fals e option for those links

    Comment

    • Frinavale
      Recognized Expert Expert
      • Oct 2006
      • 9749

      #3
      TextBoxes with TextMode="Passw ord" will clear their contents after posting back to the server. That means that after you click your button (which posts back to the server) the password field will be cleared and so your RequiredField validator will show the error message.

      -Frinny

      Comment

      • jagdeep gupta
        New Member
        • Aug 2010
        • 98

        #4
        so how to solve this problem

        Comment

        • jagdeep gupta
          New Member
          • Aug 2010
          • 98

          #5
          Code:
          <%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="setting.aspx.cs" Inherits="setting" Title="Untitled Page" %>
          <asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
          <asp:Panel ID="cppanel" runat="server" BorderWidth="2" BorderColor="DarkGray" BackColor="DarkGray" Width=100% Height="1px">
              <br />
              
          <asp:Label ID="cplable" runat="server" BackColor="DarkGray" Text="Change Password" Font-Bold="True" Font-Size="X-Large" Width="245px"></asp:Label></asp:Panel>
              <br />
              <br />
              <br />
              <asp:Panel ID="cpppassword" runat="server" Width="563px">
              <table align="center">
              <tr>
              <td style="width: 193px">
                  &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
              <asp:Label ID="cplodlpassword" runat="server" Text="Enter Old Password"></asp:Label>
              </td>
              <td style="width: 357px">
                  <br />
              <asp:TextBox ID="cptoldpassword" runat="server" TextMode="Password"></asp:TextBox>
                  <asp:RequiredFieldValidator ID="cprfvoldpassword" runat="server" ErrorMessage="Required*" ControlToValidate="cptoldpassword"></asp:RequiredFieldValidator>
                  <br />
              </td>
              </tr>
              <tr>
              <td>
                  &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
              
              <asp:Label ID="cplnewpassword" runat="server" Text="Enter New Password"></asp:Label></td>
           <td style="width: 357px">
               <br />
              <asp:TextBox ID="cptnewpassword" runat="server" TextMode="Password"></asp:TextBox><asp:RequiredFieldValidator ID="cprfvnewpassword" runat="server" ErrorMessage="Required*" ControlToValidate="cptnewpassword"></asp:RequiredFieldValidator><br />
           </td>
           </tr>
           <tr>
           <td>
               &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;
           <asp:Label ID="cplconfirmpassword" runat="server" Text="Confirm Password"></asp:Label>
           </td>
           <td style="width: 357px">
               <br />
           <asp:TextBox ID="cptconfirmpassword" runat="server" TextMode="Password" ></asp:TextBox>
           <asp:RequiredFieldValidator ID="cprfvconfirmpassword" runat="server" ErrorMessage="Required*" ControlToValidate="cptconfirmpassword" ></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="CompareValidator1" runat="server" ErrorMessage="Not Match*"  ControlToCompare="cptnewpassword" ControlToValidate="cptconfirmpassword"></asp:CompareValidator>
               <br />
           </td>
           
           </tr>
           <tr>
           <td colspan="2">
               &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
               &nbsp; &nbsp; &nbsp;&nbsp;
           <asp:Button ID="cpbchangepassword" runat="server" Text="Change Password" OnClick="cpbchangepassword_Click" />
           </td>
           </tr>
           </table>
              </asp:Panel>
              
          </asp:Content>

          Comment

          • Frinavale
            Recognized Expert Expert
            • Oct 2006
            • 9749

            #6
            You can try to set the TextBox.Text property to the value that it contains in your server-side code (maybe in the Page Load or Page PreRender event).

            -Frinny

            Comment

            • jagdeep gupta
              New Member
              • Aug 2010
              • 98

              #7
              Code:
               protected void cpbchangepassword_Click(object sender, EventArgs e)
                  {
                      
                      com = new SqlCommand("Update register Set password='"+cptnewpassword.Text+"' Where loginname=@loginname AND password='"+cptoldpassword.Text+"'", con);
                      com.Parameters.Add("@loginname", SqlDbType.NVarChar).Value = Session["username"].ToString();
                         try
                          {
                              if (con.State == ConnectionState.Closed)
                                  con.Open();
                              dr = com.ExecuteReader();
                              if (dr.Read())
                              {
                                  Response.Write("your pas has  change");
                              }
                              else
                              {
                                  Response.Write("your");
              
                              }
                
              
                          }
                          catch (Exception exc)
                          {
                          }
                          finally
                          {
                              con.Close();
                          }
                  }

              Why Else part Is executed in this?

              Comment

              • mzmishra
                Recognized Expert Contributor
                • Aug 2007
                • 390

                #8
                You must refer msdn to get the differrence between ExecuteReader
                ExecuteNonQuery
                ExecuteScalar

                and when to use which method while working on ado.net.

                Comment

                • jagdeep gupta
                  New Member
                  • Aug 2010
                  • 98

                  #9
                  But generally in other cass this does not happens why in this case

                  Comment

                  • Frinavale
                    Recognized Expert Expert
                    • Oct 2006
                    • 9749

                    #10
                    Because the dr.Read() method returned false....

                    Comment

                    Working...