ASP.NET – How to retrieve an argument manually wired up with GetPostBackClientHyperlink

Posted: 11/19/2013

Scenario:

You have wired up a link/button on the page with Page.ClientScript.GetPostBackClientHyperlink, passed it an argument and you need to retrieve that argument whenever the event is fired for the said link/button.

Solution:

In the event in question, you will want to put a check in to make sure that the __EVENTTARGET is the UniqueID of control in question and then you will want to pull out the __EVENTARGUMENT value form the request. Here are examples in VB.Net and C#:

VB.Net

    Dim arg As String = ""
    If Request.Params("__EVENTTARGET") = linkDeleteGoal.UniqueID Then
        arg = Request.Params("__EVENTARGUMENT")
    End If

C#

    string arg = "";
    if (Request.Params("__EVENTTARGET") == linkDeleteGoal.UniqueID) {
        arg = Request.Params("__EVENTARGUMENT");
    }