IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

ASP.NET Discussion :

Retour de Formulaire Dynamique


Sujet :

ASP.NET

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2014
    Messages
    75
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Octobre 2014
    Messages : 75
    Par défaut Retour de Formulaire Dynamique
    Bonjour,

    je sollicite votre aide pour la création de formulaire dynamique.
    après avoir remplis mon formulaire lorsque que je click sur le boutton "btnSubmit" il me retourne qu'il n'y a pas de contrôleur dans le panel "pnlForm"; le "pnlForm.Controls.Count" ligne 37, me retourne 0
    c'est comme si le Page.PostBack s'effectué avant le btnSubmit.Click, de plus et le résultat du "Viewstate" que je passe en debug ne s'affiche dans le "litRsltDebug" qu'après un deuxième clique

    merci d'avance

    Code asp : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
            <section>
    		    <article class="container full">
    			    <div class="row">
                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 col-h ">
                            <asp:panel id="pnlForm" cssclass="col-lng" runat="server" />
                            <asp:Button ID="btnSubmit" Text="submit"  runat="server" />
                        </div>
     
                        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12 col-h text-center">
    				        <asp:literal ID="litRslt" Text="RSLT" runat="server"  /> 
    				        <asp:literal ID="litRsltDebug" Text="N/A" runat="server" />
                        </div>
    			    </div>
    		    </article>
            </section>



    Code VB.NET : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    Imports Newtonsoft.Json
     
    Partial Class Page_DynamicForm
        Inherits System.Web.UI.Page
     
        Private BagDatasFormRlst As String = ""
        Private BagDatasFormDebug As String = ""
     
        Private Sub Page_DynamicForm_Load(sender As Object, e As EventArgs) Handles Me.Load
            If Not Page.IsPostBack Then
                LoadFormConstruct()
                ViewState("BagDatasFormRlst") = BagDatasFormRlst
                ViewState("BagDatasFormDebug") = BagDatasFormDebug
            Else
                BagDatasFormRlst = ViewState("BagDatasFormRlst")
                BagDatasFormDebug = ViewState("BagDatasFormDebug")
            End If
            litRsltDebug.Text = BagDatasFormDebug & "<br/>" & BagDatasFormRlst
            If BagDatasFormRlst <> "" Then ViewRslt(BagDatasFormRlst)
        End Sub
     
        Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
            Dim debug As String = Now.ToString & "<br/>"
            Dim DT_Rslt As New DataTable
            Try
                DT_Rslt = GetTblRslt()
            Catch ex As Exception
                ConsoleLogJS(Me.Page, "(btnSubmit_Click) " & "LOAD DT_RSLT : " & ex.ToString, "x")
                debug &= "(btnSubmit_Click) " & "LOAD DT_RSLT : " & ex.ToString & "<br/>"
            End Try
     
            Try
                If (DT_Rslt IsNot Nothing) Then
                    Dim datas As New Dictionary(Of String, String)
     
                    ConsoleLogJS(Me.Page, "ctrl.count :  " & pnlForm.Controls.Count, "x")
                    For Each ctrl As Control In pnlForm.Controls
                        debug &= "ctrl :  " & ctrl.ID
                        ConsoleLogJS(Me.Page, "ctrl :  " & ctrl.ID, "x")
                        If TypeOf ctrl Is System.Web.UI.WebControls.RadioButton Then
                            Dim rbt As System.Web.UI.WebControls.RadioButton = DirectCast(ctrl, System.Web.UI.WebControls.RadioButton)
                            datas.Add(rbt.ID, rbt.Checked)
                        End If
                        If TypeOf ctrl Is System.Web.UI.WebControls.CheckBox Then
                            Dim chk As System.Web.UI.WebControls.CheckBox = DirectCast(ctrl, System.Web.UI.WebControls.CheckBox)
                            datas.Add(chk.ID, chk.Checked)
                        End If
                        If TypeOf ctrl Is System.Web.UI.WebControls.TextBox Then
                            Dim tbx As System.Web.UI.WebControls.TextBox = DirectCast(ctrl, System.Web.UI.WebControls.TextBox)
                            datas.Add(tbx.ID, tbx.Text)
                        End If
                    Next
                    ' ///////////////////////////
                    If datas.Count > 0 Then
                        Dim i As Integer = 0
                        For Each kvp As KeyValuePair(Of String, String) In datas
                            Dim k As String = kvp.Key
                            Dim v As String = kvp.Value
                            DT_Rslt.Rows(0)("idInput" & i.ToString & "DT") = kvp.Key
                            DT_Rslt.Rows(0)("valueInput" & i.ToString & "DT") = kvp.Value
                            i += 0
                        Next
                    Else
                        ConsoleLogJS(Me.Page, "(btnSubmit_Click) " & "datas : NOT DATAS !!!", "x")
                        debug &= "(btnSubmit_Click) " & "datas : NOT DATAS !!!" & "<br/>"
                    End If
                    BagDatasFormRlst = JsonConvert.SerializeObject(DT_Rslt)
                Else
                    ConsoleLogJS(Me.Page, "(btnSubmit_Click) " & "DT_RSLT : NOT EXIST !!!", "x")
                    debug &= "(btnSubmit_Click) " & "DT_RSLT : NOT EXIST !!!" & "<br/>"
                End If
            Catch ex As Exception
                ConsoleLogJS(Me.Page, "(btnSubmit_Click) " & "Try Form : " & ex.ToString, "x")
                debug &= "(btnSubmit_Click) " & "Try Form : " & ex.ToString & "<br/>"
            End Try
     
            BagDatasFormDebug = debug
     
            ViewState("BagDatasFormRlst") = BagDatasFormRlst
            ViewState("BagDatasFormDebug") = BagDatasFormDebug
        End Sub
     
     
    #Region "ViewRslt"
        Private Sub ViewRslt(datas As String)
            If datas <> "" Then
                ConsoleLogJS(Me.Page, "(ViewRslt) " & datas, "x")
                Dim output As String = ""
                Try
                    Dim DT_Rslt As New DataTable
                    Try
                        DT_Rslt = GetTblRslt()
                        DT_Rslt = JsonConvert.DeserializeObject(Of DataTable)(datas)
                    Catch ex As Exception
                        ConsoleLogJS(Me.Page, "(btnSubmit_Click) " & "LOAD DT_RSLT : " & ex.ToString, "x")
                    End Try
     
                    If DT_Rslt.Rows.Count > 0 Then
                        Dim itemId As String = "", itemValue As String = ""
                        For i = 0 To DT_Rslt.Rows.Count - 1
                            For j = 0 To nbColTblRslt
                                itemId = CStr(DT_Rslt.Rows(i)("idInput" & j.ToString & "DT"))
                                itemValue = CStr(DT_Rslt.Rows(i)("valueInput" & j.ToString & "DT"))
     
                                output &= itemId & " : " & itemValue & ";" & "<br/>"
                            Next
                        Next
                        litRslt.Text = output
                    Else
                        ConsoleLogJS(Me.Page, "(ViewRslt) " & "NOT RSLT !", "dbg")
                    End If
                Catch ex As Exception
                    ConsoleLogJS(Me.Page, "(ViewRslt) " & ex.ToString, "x")
                End Try
            Else
                ConsoleLogJS(Me.Page, "(ViewRslt) " & "NOT DATAS !", "dbg")
            End If
        End Sub
    #End Region
     
    #Region "FormConstruct"
        Private Sub LoadFormConstruct()
            Dim DT As New DataTable
            Try
                DT = GetListOfInput()
            Catch ex As Exception
                ConsoleLogJS(Me.Page, "(LoadFormConstruct) " & "LOAD DATAS_INPUT : " & ex.ToString, "x")
            End Try
     
            Try
                If DT.Rows.Count > 0 Then
                    Dim id As String = "", title As String = "", describe As String = "", value As String = ""
                    Dim type As String = "", tooltip As String = "", enabled As Boolean = False, groupname As String = ""
                    For i As Integer = 0 To DT.Rows.Count - 1
                        id = CStr(DT.Rows(i)("idDT").ToString())
                        type = CStr(DT.Rows(i)("typeDT").ToString())
                        tooltip = CStr(DT.Rows(i)("tooltipDT").ToString())
                        value = CStr(DT.Rows(i)("valueDT").ToString())
                        enabled = CBool(DT.Rows(i)("enabledDT"))
                        groupname = CStr(DT.Rows(i)("groupNameDT").ToString())
     
                        title = CStr(DT.Rows(i)("titleDT").ToString())
                        'describe = CStr(DT.Rows(i)("describeDT").ToString())
     
                        If type <> "" Then
                            Dim lbl As New System.Web.UI.WebControls.Label : lbl.ID = id & "LBL" : lbl.Text = title
     
                            Dim dCtrl As Object = Nothing
                            If type = "tbx" Or type = "txt" Then
                                Dim tbx As New System.Web.UI.WebControls.TextBox
                                tbx.ID = id
                                tbx.Text = value
                                tbx.ToolTip = tooltip
                                tbx.Enabled = enabled
                                If type = "txt" Then tbx.TextMode = TextBoxMode.MultiLine
                                dCtrl = tbx
                            End If
                            If type = "chk" Then
                                Dim chk As New System.Web.UI.WebControls.CheckBox
                                chk.ID = id
                                chk.Checked = If(((LCase(value) = "true") Or (value = "1")), (True), (False))
                                chk.ToolTip = tooltip
                                chk.Enabled = enabled
                                dCtrl = chk
                            End If
                            If type = "rbt" Then
                                Dim rbt As New System.Web.UI.WebControls.RadioButton
                                rbt.ID = id
                                rbt.Checked = If(((LCase(value) = "true") Or (value = "1")), (True), (False))
                                rbt.ToolTip = tooltip
                                rbt.Enabled = enabled
                                If groupname <> "" Then rbt.GroupName = groupname
                                dCtrl = rbt
                            End If
     
                            If dCtrl IsNot Nothing Then
                                Dim pnl As New System.Web.UI.WebControls.Panel
                                pnl.ID = id & "PNL"
                                pnl.CssClass = "col-lg-12 col-md-12 col-sm-12 col-xs-12 col-h"
                                pnl.Controls.Add(dCtrl)
                                If title <> "" Then pnl.Controls.Add(lbl) : pnl.Controls.Add(New LiteralControl("<br/>"))
                                pnl.Controls.Add(dCtrl)
                                ' ///////////////////////////////////////////////////
                                pnlForm.Controls.Add(pnl)
                                'If title <> "" Then pnlForm.Controls.Add(lbl) : pnlForm.Controls.Add(New LiteralControl("<br/>"))
                                'pnlForm.Controls.Add(dCtrl)
     
                            Else
                                ConsoleLogJS(Me.Page, "(LoadFormConstruct) " & "(" & id & ")" & title & " : IS NOTHING !!!", "x")
                            End If
                        Else
                            ConsoleLogJS(Me.Page, "(LoadFormConstruct) " & "(" & id & ")" & title & " : NO TYPE !!!", "x")
                        End If
                    Next
                Else
                    ConsoleLogJS(Me.Page, "(LoadFormConstruct) " & "DATAS_INPUT : EMPTY !!!", "x")
                End If
            Catch ex As Exception
                ConsoleLogJS(Me.Page, ex.ToString, "x")
            End Try
        End Sub
    #End Region
     
     
    #Region "FAKE_DATAS"
     
        Private Function GetListOfInput() As DataTable
            Dim output As New DataTable
            Try
                output = GetTblInput()
     
                Dim id As Integer = 0
                Dim i1 As Integer = GetRandomInt(1, 4)
                For i = 0 To i1
                    id += 1
                    output.Rows.Add("dInputTbx" & id, "tbx", "tbx" & i.ToString, "", "", True, "", "", "")
                Next
     
                Dim i2 As Integer = GetRandomInt(2, 4)
                For i = 0 To i2
                    id += 1
                    output.Rows.Add("dInputChk" & id, "chk", "chk" & i.ToString, "", "", True, "", "", "")
                Next
     
                Dim i3 As Integer = GetRandomInt(1, 2)
                For i = 0 To i3
                    id += 1
                    output.Rows.Add("dInputTxt" & id, "txt", "txt" & i.ToString, "", "", True, "", "", "")
                Next
     
                Dim i4 As Integer = GetRandomInt(2, 4)
                For i = 0 To i4
                    id += 1
                    output.Rows.Add("dInputRbl" & id, "rbt", "rbt" & i.ToString, "", "", True, "rbt", "", "")
                Next
            Catch ex As Exception
     
            End Try
     
            Return output
        End Function
     
        Private Function GetTblInput() As DataTable
            Dim output As New DataTable
            output.Columns.Add("idDT", GetType(String))
            output.Columns.Add("typeDT", GetType(String))
            output.Columns.Add("titleDT", GetType(String))
            output.Columns.Add("valueDT", GetType(String))
            output.Columns.Add("tooltipDT", GetType(String))
            output.Columns.Add("enabledDT", GetType(Boolean))
            output.Columns.Add("groupNameDT", GetType(String))
            output.Columns.Add("cssClassDT", GetType(String))
            output.Columns.Add("cssStyleDT", GetType(String))
     
            Return output
        End Function
     
        Private nbColTblRslt As Integer = 50
        Private Function GetTblRslt() As DataTable
            Dim output As New DataTable
            For i = 0 To nbColTblRslt
                output.Columns.Add("idInput" & i.ToString & "DT", GetType(String))
                output.Columns.Add("valueInput" & i.ToString & "DT", GetType(String))
            Next
     
            Return output
        End Function
    #End Region
     
    #Region "ConsoleLog"
        Private Sub ConsoleLogJS(ByVal pPage As Page, ByVal pMsg As String, Optional ByVal pType As String = "", Optional ByVal pMethode As String = "")
            If pType = "e" Or pType = "event" Then
                pType = "[EVENT] : "
            ElseIf pType = "x" Or pType = "err" Then
                pType = "[ERROR] : "
            ElseIf pType = "d" Or pType = "dbg" Then
                pType = "[DEBUG] : "
            ElseIf pType = "c" Or pType = "call" Then
                pType = "[CALL] : "
            ElseIf pType = "w" Or pType = "warn" Then
                pType = "[WARNING] : "
            End If
     
            If pMsg <> "" Then
                If (LCase(pMethode) = LCase("PageLoadEvent")) Then
                    ScriptManager.RegisterOnSubmitStatement(pPage, pPage.GetType(), Guid.NewGuid().ToString, "console.log('" & pType & HttpContext.Current.Server.HtmlEncode(ToolsText.FormatTextDisplayMsg(pMsg)) & "');")
                ElseIf (LCase(pMethode) = LCase("ClickEvent")) Then
                    ScriptManager.RegisterClientScriptBlock(pPage, pPage.GetType(), Guid.NewGuid().ToString, "console.log('" & pType & HttpContext.Current.Server.HtmlEncode(ToolsText.FormatTextDisplayMsg(pMsg)) & "');", True)
                Else
                    ScriptManager.RegisterStartupScript(pPage, pPage.GetType(), Guid.NewGuid().ToString, "console.log('" & pType & HttpContext.Current.Server.HtmlEncode(ToolsText.FormatTextDisplayMsg(pMsg)) & "');", True)
                End If
            End If
        End Sub
    #End Region 
     
    #Region "Tools"
        Private Function GetRandomInt(ByVal Min As Integer, ByVal Max As Integer) As Integer
            Dim Generator As System.Random = New System.Random()
            Return Generator.Next(Min, Max)
        End Function
    #End Region 
     
    End Class

  2. #2
    Membre Expert Avatar de Phil Rob
    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2013
    Messages
    1 613
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2013
    Messages : 1 613
    Par défaut
    Je ne sais pas comment tu as fait mais manifestement, ta discussion a été déplacée ... !
    J'espère que tu auras les réponses que tu attends.
    Bon dimanche ...

  3. #3
    Membre confirmé
    Homme Profil pro
    Développeur .NET
    Inscrit en
    Octobre 2014
    Messages
    75
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : France, Haute Garonne (Midi Pyrénées)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Octobre 2014
    Messages : 75
    Par défaut
    Un modo est surement passé par là :p

    J'ai trouvé quelques pistes, en remontant le formulaire lors du postback via le système de ViewState, mais cela ne m'intéresse pas forcément, après si c'est nécessaire, c'est tout, hein xD
    Cependant j'ai tout de même besoin de Click sur le bouton, pour avoir les données de résultat s'afficher.

  4. #4
    Membre Expert Avatar de Phil Rob
    Homme Profil pro
    Retraité
    Inscrit en
    Novembre 2013
    Messages
    1 613
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations professionnelles :
    Activité : Retraité

    Informations forums :
    Inscription : Novembre 2013
    Messages : 1 613
    Par défaut
    Merci au modo ...

    La programmation pour le Web n'a jamais été mon truc et donc, ASP non plus.
    Je t'envoie un petit texte : ObjetPage.pdf. C'est un extrait de notes très élémentaires concernant l'objet Page et son ViewState. Je ne suppose pas que cela t'apprendra beaucoup mais peut-être que cela pourra t'initier une idée utile.

    Bon travail ...

  5. #5
    Membre confirmé
    Homme Profil pro
    Étudiant
    Inscrit en
    Juin 2006
    Messages
    132
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Juin 2006
    Messages : 132
    Par défaut
    Lors du PostBack, il faut que tu recrée ton formulaire afin que les contrôleurs soit accessibles

Discussions similaires

  1. Validation formulaire dynamique
    Par odelayen dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 31/08/2005, 17h47
  2. [JSF] Implémentation d'un formulaire dynamique
    Par Fleep dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 01/03/2005, 19h00
  3. pb access formulaire dynamique
    Par jibouze dans le forum IHM
    Réponses: 3
    Dernier message: 12/01/2005, 09h39
  4. formulaire dynamique
    Par shirya dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 19/10/2004, 16h13
  5. [struts]Formulaire dynamique
    Par GreenJay dans le forum Struts 1
    Réponses: 8
    Dernier message: 28/05/2004, 16h35

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo