2015-03-26 2 views
0

У меня есть форма, в которой я использую поле ввода с именем Password1. после обратной передачи мне нужно сохранить значение в пароле, используя viewstate. Как я могу сделать это в ASP.NET. Мой код предназначен для регистрационной формы, в которой я дал поле пароля. Я дал автоотбедренность для раскрывающегося списка. когда происходит автоматическая обратная передача, поле пароля становится пустым. вместо этого мне нужно поддерживать значение пароля как есть.Использовать viewstate для сохранения пароля в asp.net

<div> 
    <%--<asp:ScriptManager runat="server"></asp:ScriptManager>--%> 
    <ajaxToolkit:ToolkitScriptManager runat="server"> 
     </ajaxToolkit:ToolkitScriptManager> 
    <h1 style="color:bisque;text-align:center;">USER FORM REGISTRATION</h1> 

    <table class="auto-style1" style="color:crimson"> 
     <tr> 
      <td class="auto-style2">First Name</td> 
      <td class="auto-style3"> 
       <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>  
      </td> 
     </tr> 
     <tr> 
      <td class="auto-style2">Last Name</td> 
      <td class="auto-style3"> 
       <asp:TextBox ID="TextBox5" runat="server"></asp:TextBox> 
     </td> 
     </tr> 
      <tr> 
      <td class="auto-style2">Password</td> 
      <td class="auto-style3"> 
       <input id="Password1" type="password" runat="server"/></td> 
     </tr> 
     <tr> 
      <td class="auto-style2">Date of Birth</td> 
      <td class="auto-style3"> 
       <asp:TextBox ID="TextBox2" runat="server" 
      ClientIDMode="Static" ReadOnly="true"></asp:TextBox>      
       <asp:Image ID="imgCal" DescriptionUrl="#.jpg" 
      AlternateText="" runat="server" /> 
       <ajaxToolkit:CalendarExtender ID="Calend" runat="server" 
      Animated="true" PopupButtonID="imgCal" TargetControlID="TextBox2"> 
      </ajaxToolkit:CalendarExtender> 

      </td> 
     </tr> 
      <tr> 
      <td class="auto-style2">Age</td> 
      <td class="auto-style3"> 
       <asp:TextBox ID="TextBox7" runat="server" 
       ClientIDMode="Static" ReadOnly="true"></asp:TextBox> 

      </td> 
     </tr> 
     <tr> 
      <td class="auto-style2">Gender</td> 
      <td class="auto-style3"> 
       <asp:RadioButtonList ID="RadioButtonList1" runat="server" 
       RepeatDirection="Horizontal"> 
        <asp:ListItem>Male</asp:ListItem> 
        <asp:ListItem>Female</asp:ListItem> 

       </asp:RadioButtonList></td> 
     </tr> 
     <tr> 
      <td class="auto-style2">Nationality</td> 
      <td class="auto-style3"> 
       <asp:DropDownList ID="DropDownList1" runat="server" 
      Width="145px" AutoPostBack="true" 
     OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"> 
        <asp:ListItem Value="0">n1</asp:ListItem> 
        <asp:ListItem Value="1">loc2</asp:ListItem> 
        <asp:ListItem Value="2">loc3</asp:ListItem> 
        <asp:ListItem Value="3">other</asp:ListItem> 
        <asp:ListItem></asp:ListItem> 

       </asp:DropDownList> 
       <asp:TextBox ID="TextBox9" runat="server" Visible="false"> 
     </asp:TextBox> 
      </td> 

     </tr> 
     <tr> 
      <td class="auto-style2">Mobile Number</td> 
      <td class="auto-style3"> 
       <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox> 
      </td> 
     </tr> 
      <asp:UpdatePanel ID="Update1" runat="server"> 
     <ContentTemplate> 
     <tr> 



      <td class="auto-style2">Residential Adress</td> 
      <td class="auto-style3"> 
       <textarea id="TextArea1" cols="20" name="TextArea1" 
      runat="server"></textarea></td> 
     </tr> 

     </ContentTemplate> 
     </asp:UpdatePanel> 

    </table> 


</div> 

ответ

1

по умолчанию текстового поля пароля не будет розничная стоимость на postback.so вам необходимо следующими способы сохранения значения на основе этого link

protected void Page_Load(object sender, EventArgs e) 
{ 
    string pwd = txtPwd.Text; 
    txtPwd.Attributes.Add("value", pwd); 
} 
Смежные вопросы