I was recently working on one of my project and needed to add postback of a button to one of the images on my Page. After doing some research I found out that it is real easy to add Postbacks to your HTML elements that support Javascript onClick event ...
Here is How ...
imgArrow.Attributes.Add("onclick", Page.GetPostBackEventReference(targetButton))
This will fire the postback event
Also sometimes you are generating anchor hyperlinks in your code behind and want the page to be posted back to the sever when someone clicks on those links rather then going to another page. Here is how to accomplish this ...
// Uses the GetPostBackEventReference method to pass the command you want to execute for e.g
// 'command1' to the RaisePostBackEvent method when the link this code creates is clicked.
lt.Text = "<a href=\"javascript:" + Page.GetPostBackEventReference(this,"Login") + "\">LogIn</a>";
Assuming lt is the Literal on the page where we want to place the link ...then in the codebehind file ..
if (Page.Request.Form["__EVENTTARGET"] == this.UniqueID)
{
switch (Page.Request.Form["__EVENTARGUMENT"])
{
case "DisplayRegUI":
break;
case "Login":
Response.Write ("Inside the Login Postback functionality.");
break;
case "Register":
break;
}
}