I want to invisible a imgbutton in repeater when username not admin.So here my code
Check username function :

Protected Sub CheckUS(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs)
        Dim Check As String = Session("UserName").ToString
        Dim Img As ImageButton = New ImageButton
        Img = DirectCast(e.Item.FindControl("DltImg"), ImageButton)
        If Check = "admin" Then
            Imgl.Visible = True
            Img.Visible = False
        End If
    End Sub

and I call function in :

<asp:Repeater ID=Rpt1 runat=server OnItemDataBound="CheckUS">

then it go this error :

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:

Line 69:             End If
Line 70:         Catch ex As Exception
Line 71:             Throw ex
Line 72:         Finally
Line 73:         End Try

Error in load data and bind to repeater.
So I need some advices.Thank 4 ur read.

Recommended Answers

All 2 Replies

The quick glance indicates that your code references Img1.Visible, yet the name of the object is simply Img.

Oops ! Sorry, Its just my bad spelling.It's not a problem.
This is my ImageButton in Template
<asp:ImageButton ID="DltImg" runat=server ImageUrl="~/images/delete.png"/>

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.