By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,843 Members | 2,311 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,843 IT Pros & Developers. It's quick & easy.

How to avoid postback on delete button inside gridview when selecting cancel confirma

P: 5
Hi to all .NET guru guys...

I have a problem in my delete button inside gridview. How to avoid postback on when i select cancel on confirmation message? But postback is okay on Ok confirmation. What happened is if I select cancel on my confirmation button, it executes the griedview postback which i assigned in my code behind. Please see my codes below...

Code beind:

protected void gvDefectCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:GridViewMouseOverColor(this);";
e.Row.Attributes["onmouseout"] = "javascript:GridViewMouseOutColor(this);";
e.Row.Attributes.Add("onclick", ClientScript.GetPostBackEventReference(gvDefectCat alog, "Select$" + e.Row.RowIndex.ToString())); }

}


HTML:

<asp:GridView ID="gvDefectCatalog" runat="server" CssClass="GridView"
DataKeyNames="defectID,defectCode"
AutoGenerateColumns="False" OnSelectedIndexChanged="gvDefectCatalog_SelectedIn dexChanged"
AllowPaging="false" Width="98%" ShowHeader="False" ShowFooter="False" EnableViewState="true" GridLines="none" CellPadding="0" CellSpacing="0"
OnRowDataBound="gvDefectCatalog_RowDataBound"
OnRowCommand="gvDefectCatalog_RowCommand"
OnRowDeleting="gvDefectCatalog_RowDeleting"
OnRowEditing="gvDefectCatalog_RowEditing"
OnRowCancelingEdit="gvDefectCatalog_RowCancelingEd it"
OnRowUpdating="gvDefectCatalog_RowUpdating">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btEdit" Text="Edit" CommandName="Edit" CausesValidation="false" runat="server" CssClass="GridViewButton" Width="35px" TabIndex="14"/>&nbsp;
<asp:Button ID="btnDelete" Text="Delete" CommandName="Delete" runat="server" CommandArgument='<%# Eval("defectID") %>' CssClass="GridViewButton" Width="40px" TabIndex="15" OnClientClick="return confirm('Are you sure you want to delete this data?')"/>&nbsp;
</ItemTemplate>
<EditItemTemplate>
<asp:Button Text="Update" CommandName="Update" CausesValidation="true" runat="server" ID="btUpdate" CssClass="GridViewButton" Width="40px" OnClientClick="ObjectVisibility('UpdateProgress')" TabIndex="12"/>&nbsp;
<asp:Button Text="Cancel" CommandName="Cancel" CausesValidation="false" runat="server" ID="btECancel" CssClass="GridViewButton" Width="40px" OnClientClick="ObjectVisibility('UpdateProgress')" TabIndex="13"/>
</EditItemTemplate>
<HeaderTemplate>
<asp:Button Text="Insert" CommandName="Insert" CausesValidation="true" runat="server" ID="btInsert" CssClass="GridViewButton" Width="40px" OnClientClick="ObjectVisibility('UpdateProgress')" TabIndex="12"/>
<asp:Button Text="Cancel" CommandName="Cancel" CausesValidation="false" runat="server" ID="btICancel" CssClass="GridViewButton" Width="40px" OnClientClick="ObjectVisibility('UpdateProgress')" TabIndex="13"/>
</HeaderTemplate>
</asp:TemplateField>

<asp:CommandField ButtonType="Link" ShowSelectButton="true" SelectText="">
<ItemStyle Width="0%" HorizontalAlign="left" VerticalAlign="Middle"></ItemStyle>
</asp:CommandField>
</ asp:GridView>
Nov 19 '07 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.