文本框无法保留提交值

时间:2013-01-24 14:17:03

标签: asp.net vb.net textbox submit

首先,请注意我使用法语进行开发,因此有些术语是法语,但元素名称是英文。如果有任何问题,请随时提出。

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

这是代码隐藏。如果您需要我的代码的其他元素,例如:javascript代码,HTML代码或任何其他内容,请随时询问。这个问题让我在最后几天疯狂,我在stackoverflow和其他论坛上阅读了很多文档但都没有成功......

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 个答案:

答案 0 :(得分:0)

我认为通过良好的调试,你将能够解决这个问题。

我肯定会从删除javascript开始,客户端代码在发回之前绝对会影响您的价值。

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

注释掉btnSubmit.click中的if代码,并且就像现在那样,因为你只是在进行测试。

总的来说,我不明白为什么价值观不存在。