Bishan
Bishan

Reputation: 15702

Add onclick event to command field in asp.net

I have this update link in DetailsView.

<asp:CommandField ShowEditButton="true" ShowCancelButton="false" ValidationGroup="VAL_1" />

When i click this link, its updates the content on the page. but i want to updates the content on the page and redirect to another page (ex: abc.aspx) after click on this.

How could i do this ?

Upvotes: 2

Views: 13210

Answers (1)

Amiram Korach
Amiram Korach

Reputation: 13286

Use the ItemCommand event:

in code behind:

protected void detailsview1_ItemCommand(Object sender, DetailsViewCommandEventArgs e)
{
    if (e.CommandName == "Update")
    {
        Response.Redirect("abc.aspx", false);
    }
}

In aspx:

<asp:DetailsView runat="server" 
     ID="detailsview1" 
     OnItemCommand="detailsview1_ItemCommand" ...

Upvotes: 8

Related Questions