Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.
ASP.NET: Append client side functions with Attributes.Add
From Wiki
Summary: The Attributes.Add method can be used to add and append client side functions.
Need help with ASP.NET? Come and ask a question in our ASP.NET Forum
NOTE: This article applies only to HTML controls. ASP.NET controls do not exhibit this behaviour.
Say, for example, we had a HTML control that already had a javascript function attached to it's onblur event e.g.
- <input id="Text1" type="text" onblur="alert('Existing Function');" runat="server" />
If we used the Attributes.Add method to add another function, when we visit the page, the first function will have been replaced by our second. Try adding this and see the results:
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
- Text1.Attributes.Add("onblur", "alert('New Function');")
- End Sub
Notice how we only get an alert for the "New Function"? To combat this, we must append the exisiting functions as well e.g.
- Text1.Attributes.Add("onblur", "alert('New Function');" & Text1.Attributes.Item("onblur"))
This Hack is part of the ASP.NET Hacks collection



LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.