Results 1 to 22 of 22

Thread: [RESOLVED] Help with check boxes in a repeater

Threaded View

  1. #1

    Thread Starter
    New Member Ameera's Avatar
    Join Date
    Aug 2012
    Posts
    8

    Resolved [RESOLVED] Help with check boxes in a repeater

    Hi

    I am trying to use a check box within a repeater in an asp.net vb application. Basically, i am have an application that allows users to create blog posts and then other users can comment on them. I am using a check box to provide the user with functionality to like the posts comments.

    When the user clicks on like, it is supposed to fire the event which will insert or update the users like record. However, this even does not seem to be firing.

    i set up the check box within a table within the repeater as follows:

    Code:
                                                    <td class = "LikeCellRepeat">
                                                        Like: <asp:CheckBox ID="chkLikeComment" 
                                                        runat="server" 
                                                        ToolTip="Like" 
                                                        AutoPostBack="True"
                                                        OnCheckedChanged="chkLikeComment_CheckedChanged"/>                                                    
                                                        <asp:ToggleButtonExtender ID="Toggle_chkLikeComment" runat="server" 
                                                        Enabled="True" 
                                                        TargetControlID="chkLikeComment" 
                                                        CheckedImageAlternateText="Liked" 
                                                        CheckedImageUrl="~/Images/Liked.png" 
                                                        UncheckedImageUrl="~/Images/Unselected.png" 
                                                        ImageHeight="19" 
                                                        ImageWidth="19">
                                                        </asp:ToggleButtonExtender>                                                        
                                                    </td>
    and here is the check changed event:

    Code:
        Protected Sub chkLikeComment_CheckedChanged(ByVal sender As Object, ByVal e As System.EventArgs)
            MsgBox("like clicked")
            Dim CommentItem As RepeaterItem = sender.NamingContainer
            Dim HiddenID As HiddenField = CType(CommentItem.FindControl("HiddenCommentID"), HiddenField)
            Dim CommentID As Integer = Convert.ToInt32(HiddenID.Value)
    
            Dim isCommentLiked As Boolean = ExistingCommentLike(CommentID)
            Dim isCommentDisliked As Boolean = ExistingCommentDislike(CommentID)
    
            If (isCommentLiked = False And isCommentDisliked = False) Then
                'user did not previously like or dislike comment, so insert record'
                AddUserCommentLike(DirectCast(sender, CheckBox).Checked, CommentID)
            Else
                'user previously liked or disliked comment, so update record'
                UpdateUserCommentLike(DirectCast(sender, CheckBox).Checked, CommentID)
            End If
    
            'Display how many likes and dislikes there are on this comment'
            DisplayCommentLikesAndDislikes()
    
        End Sub
    i included a Msgbox in the event to see if i would at least get that and then the problem might be something else, but i don't even get the msgbox to pop up which is why i'm thinking the check changed event is not even firing.

    I've been searching the net for solutions on how to get it to fire, but what i've found so far either does not work or i am not using it properly. I saw something about re-subscribing to the event in repeater's on item data bound, and tried to set up that the way they had, but i am not sure if i did it right, as i get an error that says the checkedchanged cannot be called directly and to use raise event instead...

    Code:
        Protected Sub rptComments_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptComments.ItemDataBound
            Dim CheckLike As CheckBox = CType(e.Item.FindControl("chkLikeComment"), CheckBox)
            CheckLike.AutoPostBack = True
    
            CheckLike.CheckedChanged += New EventHandler(chkLikeComment_CheckedChanged)
        End Sub
    I have been trying to get this to work for about a week now with no luck. Would appreciate any help i can get...

    Thanks!
    Last edited by gep13; Aug 12th, 2012 at 08:54 AM. Reason: Added Code Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width