This post originated from an RSS feed registered with .NET Buzz
by Eric Wise.
Original Post: Page.GetPostBackEventReference()
Feed Title: Eric Wise
Feed URL: /error.htm?aspxerrorpath=/blogs/eric.wise/rss.aspx
Feed Description: Business & .NET
Interesting find at work today. One of my developers had two asp:image controls positioned to the right and left of a button. The developer wanted on the click of an image to call the button postback. I had no idea that the GetPostBackEventReference(control) even existed until Brendan pointed me to it (thanks buddy).
PrivateSub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) HandlesMyBase.Load IfNot Page.IsPostBack Then imgLeft.Attributes.Add("onclick", Page.GetPostBackEventReference(myButton)) imgRight.Attributes.Add("onclick", Page.GetPostBackEventReference(myButton)) EndIf EndSub
Is this "Coding Better"? Hell if I know, it seems to work though.