0

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
        Else
            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.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by boycuoi
0

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

0

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"/>

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.