Reputation: 26190
So I made each row of a GridView clickable using this method:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["OnClick"] = Page.ClientScript.GetPostBackEventReference(GridView1, "Select$" + e.Row.RowIndex.ToString());
}
}
So that when I click a row, the program redirects to Page1 via the GridView.SelectedRowChanged method.
Each row also contains some a HyperLink that is supposed to redirect to Page2. However, clicking on the HyperLink only redirects to Page1 because the SelectedRowChanged event fires first.
How do I redirect to the correct page when the HyperLink is clicked? Is it as simple as making the HyperLinks LinkButtons and executing the Click method?
Upvotes: 2
Views: 298
Reputation: 7941
You have to check if the target control is an anchor, ignore postback execution. Check the following instance.
<div onclick="if(event.target.tagName != 'A') { alert('Foo'); }" style="width: 100px; height: 100px;">
<a href="Default.aspx">Home</a>
</div>
Upvotes: 1
Reputation: 26190
Turns out it is as easy as making the HyperLinks LinkButtons and executing the Click method. Who knew?
Upvotes: 0