dragsl4y3r
dragsl4y3r

Reputation: 55

Onclick event not firing from individual cell click

I am trying to fire an onclick event for whenever an individual cell in my gridview is clicked, but it is not calling the function. I also tried adding ("onclick", "Btn_AddNewSite_Click(sender, e)") and that did not work either. Any pointers in the right direction would be great.

e.Row.Cells[column].Attributes.Add("onclick", "Btn_AddNewSite_Click()");

protected void Btn_AddNewSite_Click(object sender, EventArgs e)
{
    ModalPopupExtender1.PopupControlID = "Panel1";
    ModalPopupExtender1.Show();
}

Upvotes: 3

Views: 661

Answers (2)

VDWWD
VDWWD

Reputation: 35544

You can do this by making sure that Btn_AddNewSite is a LinkButton.

<asp:LinkButton ID="Btn_AddNewSite" runat="server" OnClick="Btn_AddNewSite_Click"></asp:LinkButton>

Then you can use the javascript code that handles the LinkButton click in the Cell by using it's UniqueID.

e.Row.Cells[column].Attributes.Add("onclick", "__doPostBack('" + Btn_AddNewSite.UniqueID + "', '')");

Upvotes: 2

Ankur
Ankur

Reputation: 33657

e.Row.Cells[column].Attributes.Add("onclick", "Btn_AddNewSite_Click()");

This will add a HTML attribute to the cell which means whenever you click the cell in the browser the browser will look for a JavaScript function called "Btn_AddNewSite_Click" which obviously is not there as this is a server side .NET function.

Upvotes: 0

Related Questions