how to show or hide div on button click in repeater in asp.net?

Diksha dudi 126 Reputation points
2022-04-28T03:27:06.56+00:00

i want to show the content on button click and hide on again button click, button and div is in repeater. Here is the code I tried , and also want the current div status hidden.

197109-screenshot-101.png197110-screenshot-102.png197195-screenshot-103.png197147-screenshot-104.png

Developer technologies | ASP.NET | Other
0 comments No comments
{count} votes

Accepted answer
  1. Lan Huang-MSFT 30,191 Reputation points Microsoft External Staff
    2022-04-28T10:09:29.477+00:00

    Hi @Diksha dudi ,
    In the repeater you can use FindControl to find the div.
    Dim sample As HtmlGenericControl = TryCast(b.Parent.FindControl("div1"), HtmlGenericControl)
    Page.FindControl(String) Method:searches the page naming container for a server control with the specified identifier.
    https://learn.microsoft.com/en-us/dotnet/api/system.web.ui.page.findcontrol?view=netframework-4.8
    You can refer to the example below.

    197298-2.jpg

    Protected Sub OnMyCommand1(ByVal sender As Object, ByVal e As CommandEventArgs)  
        Dim b As LinkButton = TryCast(sender, LinkButton)  
        Dim sample As HtmlGenericControl = TryCast(b.Parent.FindControl("div1"), HtmlGenericControl)  
      
        If b IsNot Nothing Then  
            Dim c As Label = CType(b.Parent.FindControl("Label1"), Label)  
      
            If c IsNot Nothing Then  
                sample.Visible = False  
                c.Text = "text changed in handler"  
                c.ForeColor = System.Drawing.Color.Green  
            End If  
        End If  
    End Sub  
    

    197258-19.gif
    Best regards,
    Lan Huang


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.