开发者

why this coding not work inside updatepanel?

Why this code doesn't work inside UpdatePanel controls I have in webform : four CheckBoxes and one TextBox

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开发者_如何学Python
                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

Coding was working fine outside the UpdatePanel ...but not working inside update panel ...what is wrong with it?


What's it not doing? Works for me when pasting your code. (Would comment above, but can't post pic.)

why this coding not work inside updatepanel?


You should set your checkboxes' autopostback to true, and assign oncheckedchanged event like this (not on 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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜