2010-11-12 5 views
0

Pourquoi ce code ne fonctionne pas à l'intérieur UpdatePanel contrôles que j'ai dans: quatre CheckBoxe formulaire en ligne s et un TextBoxpourquoi ce codage ne fonctionne pas à l'intérieur de updatepanel?

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 
     Dim str As String = Nothing 
     Dim id As String = Nothing 
     Dim ch As String = Nothing 
     For Each ctrl As Control In UpdatePanel1.Controls 

      If ctrl.GetType() Is GetType(CheckBox) Then 
       Dim chk As CheckBox = ctrl 
       If chk.Checked = True Then 
        If TextBox1.Text = "" Then 
         TextBox1.Text = chk.ID 
        Else 
         Dim SearchString As String = chk.ID 
         id = TextBox1.Text 
         If id.Contains(SearchString) <> -1 Then 
          TextBox1.Text = TextBox1.Text + "," + chk.ID 
         Else 

         End If 

        End If 
       Else 
        Dim SearchString As String = chk.ID 
        id = TextBox1.Text 
        If id.Contains(SearchString) <> -1 Then 

        Else 
         id = RemoveSubString(id, chk.ID) 
         TextBox1.Text = id 
        End If 

       End If 

      End If 
     Next 
    End Sub 



    Private Function RemoveSubString(ByVal stringvalue As String, ByVal stringremove As String) As String 
     Dim pos As Integer = stringvalue.IndexOf(stringremove) 
     If pos > 0 Then 
      Return stringvalue.Remove(pos - 1, stringremove.Length + 1) 
     ElseIf pos = 0 Then 
      If stringvalue.Contains(",") <> -1 Then 
       Return stringvalue.Remove(pos, stringremove.Length) 
      Else 
       Return stringvalue.Remove(pos, stringremove.Length + 1) 
      End If 

     End If 
     Return stringvalue 
    End Function 

codage fonctionnait très bien en dehors du UpdatePanel ... mais pas travailler à l'intérieur panneau de mise à jour ... ce a t-il tort?

+0

Pas besoin de crier, sauf si vous avez dépassé votre date limite. ALL CAPS est en ligne criant. DONT –

+0

@astander OP peut ne pas être au courant! Tu pourrais mieux le changer? –

+0

@Quintin Robinson l'a déjà fait. –

Répondre

0

Qu'est-ce qu'il ne fait pas? Fonctionne pour moi lorsque vous collez votre code. (Commenterait ci-dessus, mais ne peut pas poster pic.)

pic

+0

Son ne fonctionne pas quand quelqu'un vérifie ckecjboxes son ID n'a pas pu être récupérer dans la zone de texte dans l'état vérifié vous avez besoin de bouton pour le faire /// –

+0

je veux lorsque l'utilisateur coche les cases à l'intérieur du panneau de mise à jour sa valeur automaticcaly récupérer dans la zone de texte lorsque la case est cochée –

0

Vous devez définir vos cases à cocher autopostback à true, et assigner événement oncheckedchanged comme celui-ci (et non sur page_load):

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
    <ContentTemplate> 
     <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged"></asp:CheckBox> 
     <asp:CheckBox ID="CheckBox2" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged"></asp:CheckBox> 
     <asp:CheckBox ID="CheckBox3" runat="server" AutoPostBack="true" OnCheckedChanged="CheckBox_CheckedChanged"></asp:CheckBox> 
     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
    </ContentTemplate> 
</asp:UpdatePanel> 

Protected Sub CheckBox_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged 
    'logic here 
    TextBox1.Text = CType(sender, CheckBox).ID 
End Sub 
+0

Mais il actualise le code .... –

+0

Ne fonctionne pas ................. –