2013-01-24 48 views
1

首先,请注意我正在法语中开发,所以有些术语是法语的,但是元素名称是英文的。如有任何问题,请随时询问。textbox在提交时不能保留价值

我正在使用vb.net的ASP网页,我有一个4文本框的形式。用户可以选择使用他的电话号码登录,或者输入他的姓,名和生日。在开始时,当我点击我的提交按钮时,一切正常,但现在,当我在文本框中输入文本时,单击提交时,我的所有文本框值都为空。验证我的表单时,它总是返回false。

这里是代码隐藏。如果您需要我的代码的其他元素,例如:javascript代码,html代码或任何其他内容,请随时询问。这个问题让我疯狂的最后几天,我读了很多关于计算器和其他论坛,但没有成功文件...

Imports System.Data.SqlClient 

Public Class WebForm1 
Inherits System.Web.UI.Page 

Protected SqlCon_PAIE As New SqlConnection 
Protected SqlCon_Gamsco As New SqlConnection 
Public Event LostFocus As EventHandler 

Private Sub Get_Value_GAMSCO() 
    Dim strSQL As String 
    Dim DatS As New DataSet 
    Dim SQLadap As SqlClient.SqlDataAdapter 

    SqlCon_Gamsco.ConnectionString = ConfigurationManager.ConnectionStrings("String_Connection_Gamsco").ConnectionString 

    strSQL = " SELECT TOP 2 * " & _ 
       " FROM [GAMSCO].[RAPPORTS]" 

    SQLadap = New SqlDataAdapter(strSQL, SqlCon_Gamsco) 
    SQLadap.Fill(DatS, "Recherche") 

    SqlCon_Gamsco.Dispose() 
End Sub 

Protected Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click 
    Dim MatriculeComplete As Boolean = False 
    Dim infosComplete As Boolean = False 
    If ((Not String.IsNullOrEmpty(txtNumber.Text)) Or (Not String.IsNullOrEmpty(txtLastName.Text) And Not String.IsNullOrEmpty(txtFirstName.Text) And Not String.IsNullOrEmpty(hfDateNaisVal.Value()))) Then 
     LblWarning.Text = "" 

     'Si le matricule n'est pas vide 
     If (hfMatricule.Value().Equals("true")) Then 
      MatriculeComplete = True 
     End If 

     'Si les infos sont complètes 
     If (Not String.IsNullOrEmpty(txtLastName.Text) And Not String.IsNullOrEmpty(txtFirstName.Text) And Not String.IsNullOrEmpty(hfDateNaisVal.Value())) Then 
      If (hfDateNais.Value().Equals("true")) Then 
       infosComplete = True 
      End If 
     End If 
    End If 
    If (MatriculeComplete = False And infosComplete = False) Then 
     LblWarning.Text = "Le matricule ou les informations personnelles sont manquantes ou incomplètes" 
    ElseIf (MatriculeComplete = True) Then 
     rechercher_employe_matricule(txtNumber.Text) 
    ElseIf (infosComplete = True) Then 
     rechercher_employe_infos(txtFirstName.Text, txtLastName.Text, hfDateNaisVal.Value()) 
    End If 
    reset_champs() 
End Sub 

Protected Sub reset_champs() 
    txtNumber.Text = "" 
    hfMatricule.Value() = "" 
    hfDateNaisVal.Value() = "" 
    hfDateNais.Value() = "" 
    txtLastName.Text = "" 
    txtFirstName.Text = "" 
End Sub 
Private Sub rechercher_employe_infos(prenom As String, nom As String, dateNais As String) 
    'Dim dateParts As String() = dateNais.Split("-") 
    'Dim dateArrange As String = dateParts(2) + "-" + dateParts(1) + "-" + dateParts(0) 
    Dim strSQL As String 
    Dim DatS As New DataSet 
    Dim SQLadap As SqlClient.SqlDataAdapter 

    SqlCon_PAIE.ConnectionString = ConfigurationManager.ConnectionStrings("String_Connection_Paie").ConnectionString 

    strSQL = " SELECT MATR, upper(left(NOM,1)) + lower(right(NOM,len(NOM)-1)) AS 'NOM', upper(left(PRNOM,1)) + lower(right(PRNOM,len(PRNOM)-1)) as 'PRENOM', DATE_NAIS" & _ 
        " FROM PAI_DOS" & _ 
        " WHERE (NOM like '%" & nom & "') AND (PRNOM like '%" & prenom & "') AND (DATE_NAIS like (convert(datetime,'" & dateNais & "')))" 

    SQLadap = New SqlDataAdapter(strSQL, SqlCon_PAIE) 
    SQLadap.Fill(DatS, "Recherche") 


    If DatS.Tables("Recherche").Rows.Count > 0 Then 
     With DatS.Tables("Recherche").Rows(0) 
      'Response.Redirect("formulaire.aspx?Mat=" & Server.UrlEncode(.Item(0))) 
     End With 
    Else 
     LblWarning.Text = "L'employé " + prenom + " " + nom + " " + dateNais + " n'existe pas dans la base de données" 
    End If 
    SqlCon_PAIE.Dispose() 
End Sub 
Private Sub rechercher_employe_matricule(matricule As String) 
    Dim strSQL As String 
    Dim DatS As New DataSet 
    Dim SQLadap As SqlClient.SqlDataAdapter 

    SqlCon_PAIE.ConnectionString = ConfigurationManager.ConnectionStrings("String_Connection_Paie").ConnectionString 

    strSQL = " SELECT MATR" & _ 
        " FROM PAI_DOS" & _ 
        " WHERE (MATR like '%" & matricule & "')" 

    SQLadap = New SqlDataAdapter(strSQL, SqlCon_PAIE) 
    SQLadap.Fill(DatS, "Recherche") 


    If DatS.Tables("Recherche").Rows.Count > 0 Then 
     With DatS.Tables("Recherche").Rows(0) 
      'Response.Redirect("formulaire.aspx?Mat=" & Server.UrlEncode(.Item(0))) 
     End With 
    Else 
     LblWarning.Text = "Le matricule " + matricule + " n'existe pas dans la base de données" 
    End If 
    SqlCon_PAIE.Dispose() 
End Sub 

Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load 
    If Not IsPostBack Then 
     txtNumber.Text = txtNumber.Text 
    End If 
End Sub 

'Protected Sub txtMatricule_TextChanged(sender As Object, e As EventArgs) Handles txtMatricule.TextChanged 
' txtMatricule.Text = txtMatricule.Text 
' MsgBox(txtMatricule.Text) 
'End Sub 
End Class 

而且aspx页面

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="accueil.aspx.vb" Inherits="Gamsco_Web.WebForm1" %> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title>Gamsco - Authentification</title> 
<link rel="stylesheet" type="text/css" href="Styles\Site.css" /> 
<link rel="stylesheet" href="http://code.jquery.com/ui/1.9.2/themes/base/jquery-ui.css" /> 
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.3.js"></script> 
<script type="text/javascript" src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"> </script> 

</head> 
<body style="text-align:center;"> 
<h1 class="header">Rapport d&#39;accident ou d&#39;événement dangereux</h1> 
<div class="page"> 
    <div class="global"> 
     <div class="subtitle">Veuillez saisir le matricule ou nom, prénom et date de naissance du blessé</div> 
     <form id="form1" runat="server" > 
      <table style="width: 65%; height: 250px; "> 
       <tr> 
        <td class="style5"> 
         <asp:Label ID="lblMatricule" runat="server" Text="Matricule:"> </asp:Label> 
        </td> 
        <td class="style6"> 
         <asp:TextBox ID="txtNumber" runat="server" Width="188px" MaxLength="9" ></asp:TextBox> 
        </td> 
        <td class="style7"> 
         <div id="errMatr" class="err"></div> 
        </td> 
       </tr> 
       <tr> 
        <td class="style2"> 
        </td> 
        <td class="style1"> 
         <strong style="text-align: justify">ou</strong> 
         <asp:HiddenField ID="hfMatricule" runat="server" /> 
         <asp:HiddenField ID="hfDateNais" runat="server" /> 
         <asp:HiddenField ID="hfDateNaisVal" runat="server" /> 
        </td> 
       </tr> 
       <tr> 
        <td class="style2"> 
         <asp:Label ID="lblNom" runat="server" Text="Nom:"></asp:Label> 
        </td> 
        <td class="style1"> 
         <asp:TextBox ID="txtLastName" runat="server" width="191px" ></asp:TextBox> 
        </td> 
        <td class="style7"> 
         <div id="errNom" class="err"></div> 
        </td> 
       </tr> 
       <tr> 
        <td class="style2"> 
         <asp:Label ID="lblPrenom" runat="server" Text="Prenom:"></asp:Label> 
        </td> 
        <td class="style1"> 
         <asp:TextBox ID="txtFirstName" runat="server" width="191px"></asp:TextBox> 
        </td> 
        <td class="style7"> 
         <div id="errPrenom" class="err"></div> 
        </td> 
       </tr> 
       <tr> 
        <td class="style3"> 
         <asp:Label ID="lblDateNaissance" runat="server" Text="Date de naissance:"></asp:Label> 
        </td> 

        <td class="style4"> 
         <input id="datepicker" class="calendar" placeholder="JJ-MM-AAAA" type="text" 
          maxlength="10" /> 
        </td> 
        <td class="style7"> 
         <div id="errDateNais" class="err"></div> 
        </td> 
       </tr> 
      </table> 
      <asp:button ID="btnSubmit" runat="server" Text="Continuer"></asp:button> 
      <br /> 
      <asp:Label ID="LblWarning" runat="server" ForeColor="Red"></asp:Label> 
     </form> 
    </div> 
</div> 
<div class="footer">test</div> 
<script src="ScriptApp/App.js" type="text/javascript"></script> 
<script src="Scripts/jquery.js" type="text/javascript"></script> 
<script src="Scripts/jquery.maskedinput-1.3.js" type="text/javascript"></script> 
<script type="text/javascript" src="Scripts/date-fr-CA.js"></script> 
</body> 
</html> 
+1

你能复制.aspx页面吗? – Junaid

+0

瞧! aspx页面在这里 –

+0

你想在'recherche' * -methods之后保留TextBox的值吗?如果你这样做,你应该在提交方法结束时删除'reset_champs()'-call。 – pleinolijf

回答

0

我认为,具有良好调试你将能够弄清楚这一点。

我肯定会开始删除JavaScript,客户端代码可能会绝对影响您的价值之前,他们被回发。

使一切变得简单,取出page.load代码,它对你没有任何好处。

注释掉btnSubmit.click中的if代码,就好像现在值已经存在一样,因为你只是在测试。

总的来说,我不明白为什么值不会在那里。