Reputation: 20468
i have some anchors in my aspx page.
i need to determine them (couse to run page_load) in page_load after click.
as you know those anchors are not regular asp.net controls and when you click them Page.IsPostBack
is always false.
i can not use linkbuttons for some reasons.
so, how can i determine those anchors in page_load after click?
thanks in advance
Upvotes: 0
Views: 1572
Reputation: 14915
A more elegant way would be to use __doPostBack function(It's already there in every asp.net page) in javascript and set appropiate event targent and event argument. This is how asp.net controls posts back to server
for example.
<a id="LinkButton1" href="javascript:__doPostBack('Anchor1','')">LinkButton</a>
On the server Side, you could handle the click event as following
protected void Anchor1_Click(object sender, EventArgs e)
{
Response.Write("Hello World !");
}
Upvotes: 1
Reputation: 3379
Well, my only idea is tu use parameters in url and use them to identify which hyperlink was clicked.
<a href="page.aspx?linkName=link1">Link 1</a>
<a href="page.aspx?linkName=link2">Link 2</a>
And in code behind
string linkName = Request.QueryString["linkName"];
if (linkName = "link1")
{ // something
}
But what's the reason you cannot use LinkButtons
or some other controls? This approach would be more convenient in ASP.NET.
Upvotes: 3