+1  A: 

From server code you could use ClientScriptManager.GetPostBackEventReference which renders out a postback event reference heres a link on msdn http://msdn.microsoft.com/en-us/library/system.web.ui.page.getpostbackeventreference.aspx

heres a sample

Allows selecting gridview row without select column.

protected override void Render(HtmlTextWriter writer)
{
GridView g = GridView1;
foreach (GridViewRow r in g.Rows)
{

if(DataControlRowType.DataRow == r.RowType)
{
r.Attributes["onMouseOver"] = "this.style.cursor='pointer';this.style.cursor='hand'";
r.Attributes["OnClick"] = ClientScript.GetPostBackEventReference(g, "Select$" + r.RowIndex, true);
}
}

base.Render(writer);
}
almog.ori
+1  A: 

Is this your web site? If so, you can probably just call the click event for the button directly (assuming it causes a postback).

Are you scraping someone else's site? In that case, use a System.Net.WebClient or System.Net.HttpWebRequest object to send a similar request to the server that the browser would send if you click the button. There are two ways to find out what the request will be:

  • Study the source of the page in question until you understand what http request is sent when you click the button. This can be especially tricky for asp.net sites because of the hidden ViewState field.
  • Use something like WireShark to sniff the packet sent and work backwards from that.
Joel Coehoorn
I know that I can use WebClient, but I still don't know how to do this work by hand.
NVA