Problème avec RequiredFieldValidator

Résolu
cs_richardjul Messages postés 7 Date d'inscription lundi 16 octobre 2006 Statut Membre Dernière intervention 24 janvier 2008 - 13 août 2007 à 15:14
cs_richardjul Messages postés 7 Date d'inscription lundi 16 octobre 2006 Statut Membre Dernière intervention 24 janvier 2008 - 14 août 2007 à 10:03
Bonjour,
j'ai un problème avec mon RequiredFieldValidator, je suis un peu novice en VB.Net mais j'essaie tant bien que mal!
Mon soucis est le suivant, dans mon gridview (ou je gère la création de rubriques et de sous-rubriques pour mon site) j'ai placé un footer ou l'admin en cours peut ajouter une nouvelle rub, et j'aimerais juste faire un test de validation si le champ est vide. Le soucis et qu'il fait ce test sur chacun des liens généré dans mon gridview alors qu'il ne devrait le faire qu'au moment ou l'on clic sur "ajouter",
quelqu'un aurait la solution, voivi mon code :

<%

@
Page
Language="VB"
AutoEventWireup="false"
CodeFile="GestionRubrique.aspx.vb"
Inherits="IHM_Default" %><%

@
Register
Src="MenuAdmin.ascx"
TagName="MenuAdmin"
TagPrefix="uc1" %><%

@
Register
Src="bandeau.ascx"
TagName="bandeau"
TagPrefix="uc2" %> 

<!

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
id="Head1"
runat="server">

<title>Gestion des rubriques
</title>

<script
src="popups.js"
type="text/javascript"></script>

<link
href="../../CSS/Styles.css"
rel="stylesheet"
type="text/css"
/>

</

head><

body><

table
id="centpourcent"><tr><td
align="center">
<

table
cellpadding="0"
cellspacing="0"
id="tb_identification"><tr><td>

<uc2:bandeau
ID="Bandeau2"
runat="server"
/>

</td></tr>

<tr><td
bgcolor="#FFFFFF"
style="height: 200px">

<form
id="form1"
runat="server">

<div>

<uc1:MenuAdmin
ID="MenuAdmin1"
runat="server"
Visible="true"
/>

<table
class="nomrub"><tr><td
width="35px"><img
align="middle"
src="Images/little_ico_rubrik.png"
/></td><td><asp:label
id="lbl_rubrique"
runat="server">ADMINISTRER LES RUBRIQUES
</asp:label></td></tr></table>

<asp:GridView
ID="gdv_rubrique"
CssClass="TblListe"
runat="server"
AllowPaging="True"
AutoGenerateColumns="False"
ShowFooter="True"

DataKeyNames="cru_id"
DataSourceID="SqlDataSource1"
EmptyDataText="Aucune rubrique">

<RowStyle
CssClass="LigneStandard"/>

<SelectedRowStyle
CssClass="LigneSelectionnee"/>

<AlternatingRowStyle
CssClass="LigneAlternee"/>

<Columns>

<asp:TemplateField
HeaderText="Rubrique"
SortExpression="rub_id">

<HeaderStyle
CssClass="Entete"
/>

<EditItemTemplate>

<!---->

<asp:Label
ID="lblEditRubId"
runat="server"
Text='<%# Bind("rub_id") %>
'></asp:Label>

</EditItemTemplate>

<ItemTemplate>

<asp:Label
ID="lblRubId"
runat="server"
Text='<%# Bind("rub_id") %>
'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:Label
CssClass="footer"
ID="lblNewRubId"
runat="server"
Text='<%# Bind("rub_id") %>
'></asp:Label>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField
HeaderText="Identifiant"
SortExpression="cru_id"
Visible="False">

<HeaderStyle
CssClass="Entete"
/>

<EditItemTemplate>

<asp:Label
ID="lblEditCruId"
runat="server"
Text='<%# Eval("cru_id") %>
'></asp:Label>

</EditItemTemplate>

<ItemTemplate>

<asp:Label
ID="lblCruId"
runat="server"
Text='<%# Bind("cru_id") %>
'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:Label
CssClass="footer"
ID="lblNewCruId"
runat="server"
Text='<%# Bind("cru_id") %>
'></asp:Label>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField
HeaderText="Libell&#233;"
SortExpression="cru_nom">

<HeaderStyle
CssClass="Entete"
/>

<EditItemTemplate>

<asp:TextBox
ID="txtEditCruNom"
runat="server"
Text='<%# Bind("cru_nom") %>
'></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<asp:LinkButton
ID="lklCruNom"
runat="server"
Text='<%# Bind("cru_nom") %>
'
CommandName="SousRubrique"
CommandArgument='<%# Eval("rub_id") %>
'></asp:LinkButton>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox
CssClass="footer"
ID="txtNewCruNom"
runat="server"
Text='<%# Bind("cru_nom") %>
'></asp:TextBox>

<asp:RequiredFieldValidator
ID="rfv_NewCruNom"
runat="server"
ErrorMessage="Libell‚ obligatoire"
ControlToValidate="txtNewCruNom"></asp:RequiredFieldValidator>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField
HeaderText="Chemin image"
SortExpression="cru_img">

<HeaderStyle
CssClass="Entete"
/>

<EditItemTemplate>

<asp:TextBox
ID="txtEditCruImg"
runat="server"
Text='<%# Bind("cru_img") %>
'></asp:TextBox>

</EditItemTemplate>

<ItemTemplate>

<asp:Label
ID="lblCruImg"
runat="server"
Text='<%# Bind("cru_img") %>
'></asp:Label>

</ItemTemplate>

<FooterTemplate>

<asp:TextBox
CssClass="footer"
ID="txtNewCruImg"
runat="server"
Text='<%# Bind("cru_img") %>
'></asp:TextBox>

</FooterTemplate>

</asp:TemplateField>

<asp:TemplateField
HeaderText="Nombre de sous rubrique"
SortExpression="nbEnfants"
Visible="False">

<HeaderStyle
CssClass="Entete"
/>

<ItemTemplate>

<asp:Label
ID="nbEnfants"
runat="server"></asp:Label>

</ItemTemplate>

</asp:TemplateField>

<asp:TemplateField
ShowHeader="False">

<HeaderStyle
CssClass="Entete"
/>

<EditItemTemplate>

<asp:ImageButton
ID="lkl_update"
runat="server"
ImageUrl="Images/b_modif.png"
CausesValidation="True"
CommandName="Update"
AlternateText='<%# UpdateLang("lkl_update") %>
'/>

&nbsp;<asp:ImageButton
ID="lkl_cancel"
runat="server"
ImageUrl="Images/b_annuler.png"
CausesValidation="False"
CommandName="Cancel"
AlternateText='<%# UpdateLang("lkl_cancel") %>
'/>

</EditItemTemplate>

<ItemTemplate>

<asp:ImageButton
ID="lkl_edit"
runat="server"
ImageUrl="Images/b_modif.png"
CausesValidation="False"
CommandName="Edit"
AlternateText='<%# UpdateLang("lkl_edit") %>
'/>

&nbsp;
<asp:ImageButton
OnClientClick="return confirm('Etes-vous s–r de vouloir supprimer cette rubrique et tout son contenu?');"
ID="lkl_delete"
runat="server"
ImageUrl="Images/b_supp.png"
CausesValidation="False"
CommandName="Delete"
AlternateText='<%# UpdateLang("lkl_delete") %>
'/>

</ItemTemplate>

<FooterTemplate>

<asp:LinkButton
CssClass="footer"
id="lkl_insert"
runat="server"
Text='<%# UpdateLang("lkl_insert") %>
'
CommandName="Insert"></asp:LinkButton>

</FooterTemplate>

</asp:TemplateField>

</Columns>

<EmptyDataTemplate>

<table
>

<tr>

<td><asp:Label
ID="lblNewCruNom"
runat="server"
Text='<%# UpdateLang("Libelle") %>
'></asp:Label></td>

<td><asp:Label
ID="lblNewCruImg"
runat="server"
Text='<%# UpdateLang("CheminImage") %>
'></asp:Label></td>

</tr>

<tr>

<td><asp:TextBox
ID="txtNewCruNom"
runat="server"
Text='<%# Bind("cru_nom") %>
'></asp:TextBox></td>

<td><asp:TextBox
ID="txtNewCruImg"
runat="server"
Text='<%# Bind("cru_img") %>
'></asp:TextBox></td>

<td><asp:LinkButton
id="lkl_insertNew"
runat="server"
Text='<%# UpdateLang("lkl_insert") %>
'
CommandName="InsertNew"></asp:LinkButton></td>

</tr>

</table>

</EmptyDataTemplate>

</asp:GridView>

<asp:SqlDataSource
ID="SqlDataSource1"
runat="server"
ConnectionString="<%$ ConnectionStrings:axorys_ConnectionString %>
"

DeleteCommand="RubriqueContenu_Delete"
DeleteCommandType="StoredProcedure"

InsertCommand="RubriqueContenu_AddNew"
InsertCommandType="StoredProcedure"

SelectCommand="RubriqueContenu_GetParentByLangueUtilisateur"
SelectCommandType="StoredProcedure"

UpdateCommand="RubriqueContenu_Update"
UpdateCommandType="StoredProcedure">

<SelectParameters>

<asp:SessionParameter
Name="cru_langue"
SessionField="cru_langue"/>

<asp:SessionParameter
Name="uti_id"
SessionField="uti_id"/>

</SelectParameters>

<DeleteParameters>

<asp:Parameter
Name="cru_id"
Type="Int32"
/>

</DeleteParameters>

<UpdateParameters>

<asp:Parameter
Name="cru_id"
Type="Int32"
/>

<asp:SessionParameter
Name="cru_langue"
SessionField="cru_langue"/>

<asp:Parameter
Name="cru_nom"
Type="String"
/>

<asp:Parameter
Name="cru_img"
Type="String"
/>

<asp:Parameter
Name="rub_id"
Type="Int32"
/>

</UpdateParameters>

<InsertParameters>

<asp:SessionParameter
Name="cru_langue"
SessionField="cru_langue"/>

<asp:Parameter
Name="cru_nom"
Type="String"
/>

<asp:Parameter
Name="cru_img"
Type="String"
/>

<asp:Parameter
Name="rub_id"
Type="Int32"
/>

</InsertParameters>

</asp:SqlDataSource>

<asp:Label
ID="Label1"
runat="server"
Visible="False"></asp:Label>

</div>

<br
/>

</form>

</td></tr></table>

</td></tr></table></

body></

html>

et le code behind:
Imports

BusinessLogicLayer
Imports

System.Data
Partial

Class IHM_Default

Inherits System.Web.UI.Page

Dim local
As Localization =
New Localization()

Protected
Sub gdv_rubrique_RowCommand(
ByVal sender
As
Object,
ByVal e
As System.Web.UI.WebControls.GridViewCommandEventArgs)
Handles gdv_rubrique.RowCommand

'Test si c'est l'admin_global (c'est le seul qui peut effectuer des op‚rations sur les rubriques de niveau 1)

If Session(
"uti_id") = 1
Or Session(
"uti_id") = 8
Then

'******************

'** POUR L'AJOUT **

'******************

If e.CommandName =
"Insert"
Then

'(JavaScript) V‚rifier si les champs obligatoires ont ‚t‚ renseign‚s

'R‚cup‚ration des champs saisis

Dim cru_nom
As TextBox = gdv_rubrique.FooterRow.FindControl(
"txtNewCruNom")

Dim cru_img
As TextBox = gdv_rubrique.FooterRow.FindControl(
"txtNewCruImg")RubriqueContenu.RubriqueContenu_AddNew(Session(

"cru_langue"), cru_nom.Text, cru_img.Text, Session(
"rub_id"))RubriqueUtilisateur.RubriqueUtilisateur_AddNew(Session(

"rub_id"), Session(
"uti_id"))

'Actualisation du GridViewgdv_rubrique.DataBind()

End
If

'**********************************************

'** POUR UN NOUVEL AJOUT (EmptyDataTemplate) **

'**********************************************

If e.CommandName =
"InsertNew"
Then

'R‚cup‚ration des champs saisis

Dim cru_nom
As
String =
CType(gdv_rubrique.Controls(0).Controls(0).FindControl(
"txtNewCruNom"), TextBox).Text

Dim cru_img
As
String =
CType(gdv_rubrique.Controls(0).Controls(0).FindControl(
"txtNewCruImg"), TextBox).TextRubriqueContenu.RubriqueContenu_AddNew(Session(

"cru_langue"), cru_nom, cru_img, Session(
"rub_id"))

'RubriqueUtilisateur.RubriqueUtilisateur_AddNew(Session("rub_id"), Session("uti_id"))Response.Redirect(

"GestionRubrique.aspx")

End
If

If e.CommandName =
"Delete"
Then

End
If

If e.CommandName =
"Edit"
Then

End
If

Elsegdv_rubrique.ShowFooter =

"False"

'Affichage du message d'erreur dans le Label1Label1.ForeColor = System.Drawing.Color.Red
Label1.Text "Contactez l'administrateur global"Label1.Visible

True

End
If

'*****************************

'** POUR LES SOUS RUBRIQUES **

'*****************************

If e.CommandName =
"SousRubrique"
ThenSession(

"rub_id_parent") = Convert.ToInt32(e.CommandArgument)Response.Redirect(

"GestionSousRubrique.aspx")

End
If

End
Sub

Protected
Sub gdv_rubrique_RowDataBound(
ByVal sender
As
Object,
ByVal e
As System.Web.UI.WebControls.GridViewRowEventArgs)
Handles gdv_rubrique.RowDataBound

'Traduction des entˆtes de colonnes du GridView

If e.Row.RowType = DataControlRowType.Header
Thene.Row.Cells.Item(0).Text = UpdateLang(

"Heading")e.Row.Cells.Item(1).Text = UpdateLang(

"Identifier")e.Row.Cells.Item(2).Text = UpdateLang(

"Name")e.Row.Cells.Item(3).Text = UpdateLang(

"CheminImage")

End
If

End
Sub

'Fonction pour traduire le texte des liens du GridView

Public
Function UpdateLang(
ByVal sValue)
As
String

Return local.GetString(sValue)

End
Function

Protected
Sub Page_Load(
ByVal sender
As
Object,
ByVal e
As System.EventArgs)
HandlesMe.LoadLabel1.Visible "false"gdv_rubrique.ShowFooter

"True"

'Initialisation des variables de session pour le fil d'arianeSession(

"rub1") =
""Session(

"rub2") =
""

'Chargement du fichier de langue

Me.local.LoadResource(Session(
"cru_langue"))

'Pour la traductionlbl_rubrique.Text = local.GetString(

"lbl_rubrique")

'R‚cup‚ration du dernier rub_id pour la langue s‚l‚ctionn‚e

Dim LastRubId
As
Integer = RubriqueContenu.RubriqueContenu_GetLastRubIdByLangue(Session(
"cru_langue"))

Dim rub_id
As
Integer = LastRubId + 1

'Test si rub_id existe d‚j…

If Rubrique.Rubrique_ExistRubId(rub_id) = 0
ThenRubrique.Rubrique_AddNew(rub_id)

End
IfSession(

"rub_id") = rub_id

'Dim myGridViewRow As GridViewRow

'For Each myGridViewRow In gdv_rubrique.Rows

' 'R‚cup‚ration du num‚ro de la rubrique

' Dim rubId As String = CType(myGridViewRow.FindControl("rub_id"), Label).Text

' 'Appel de la requˆte pour avoir le nombre de sous rubrique

' Dim nbSousRubrique As String = CType(RubriqueContenu.RubriqueContenu_GetNbEnfantByLangue(Session("cru_langue"), rubId), String)

' Dim nbEnfants As Label = myGridViewRow.FindControl("NbEnfants")

' nbEnfants.Text = nbSousRubrique

'Next

'Dim dtRubriqueContenu As DataTable = RubriqueContenu.RubriqueContenu_GetParentByLangueUtilisateur(Session("cru_langue"), Session("uti_id"))

'For Each drRubriqueContenu As DataRow In dtRubriqueContenu.Rows

' recupDonnee(drRubriqueContenu)

'Next

End
Sub

'Public Sub recupDonnee(ByVal drRubriqueContenu As DataRow)

' Dim myGridViewRow As GridViewRow

' For Each myGridViewRow In gdv_rubrique.Rows

' 'R‚cup‚ration du num‚ro de la rubrique

' Dim rub_id As String = CType(myGridViewRow.FindControl("rub_id"), Label).Text

' 'Appel de la requˆte pour avoir le nombre de sous rubrique

' Dim nbSousRubrique As String = CType(RubriqueContenu.RubriqueContenu_GetNbEnfantByLangue(Session("cru_langue"), rub_id), String)

' Dim nbEnfants As Label = myGridViewRow.FindControl("NbEnfants")

' nbEnfants.Text = nbSousRubrique

' Next

'End SubEnd

ClassMerci beaucoup pour vos remarques et vos réponses,
@ bientôt

Julien RICHARD
Adjoint Multimedia
Groupe AXORYS

2 réponses

jesusonline Messages postés 6814 Date d'inscription dimanche 15 décembre 2002 Statut Membre Dernière intervention 13 octobre 2010 29
13 août 2007 à 15:58
bonjour,

utilise la propriété validationgroup de ton button, de ton validateur  et de ton textbox. Il faut qu'ils ait la meme value.

<hr />Cyril - MSP - MCPD ASP.net & MCTS SQL
3
cs_richardjul Messages postés 7 Date d'inscription lundi 16 octobre 2006 Statut Membre Dernière intervention 24 janvier 2008
14 août 2007 à 10:03
C'est bien ça thanks a lot jesusonline! je vais integrer ça sur tous mes controles,
 merci encore pour ta rapidité de réponse ça fait super plaisir...
@++

Julien RICHARD
Adjoint Multimedia
Groupe AXORYS
0
Rejoignez-nous