onmouseover event for dynamic controls

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jay123
    New Member
    • Sep 2008
    • 121

    onmouseover event for dynamic controls

    Hi,
    I have ListView and in that ListView their are some Imagebuttons
    1) Edit
    2) Update
    3) Cancel

    I want to add 'onmouseover' event to all of these buttons for some user.

    i am trying this on page_load
    Code:
    If(DummyUser)
    EditButton.Attributes.Add("onmouseover", "this.src='../Images/abc.gif'")
    End If
    but this give me an error as 'System.NullRef erenceException : Object reference not set to an instance of an object', which i think occurs as above buttons are dynamically created depending upon no. of records in listview and i am trying to add an attribute before the controls is actually rendered. I have tried this code in every event as Pre_init to pre_render but doesnt work

    I can add onmouseover event directly into ImageButtons HTML code and they work but then i dont want this effect to be seen by every user.Is their anyway around this so that i can achieve this onmouseover effect.

    I am using vb.net for developing this.

    Any help will be appreciated.

    Regards
    Jay
  • jay123
    New Member
    • Sep 2008
    • 121

    #2
    Me answering me :)
    As Control is dynamic, we cant add onmouseover attributes rather any attributes if the controls isnt visible.

    work around would be on Daragrid_ItemBo und, try finding that control and if it exist add an attributes. Ex
    Code:
    Dim EdButton As ImageButton = DirectCast(e.Item.FindControl("Button1"), ImageButton)
                If Not (EdButton Is Nothing) Then
                    EdButton.Attributes.Add("onmouseover", "this.src='../Images/test.gif'")
                    EdButton.Attributes.Add("onmouseout", "this.src='../Images/test1.gif'")
                End If

    Comment

    Working...