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(o bject sender, GridViewRowEven tArgs e)
{
if (e.Row.RowType == DataControlRowT ype.DataRow)
{
e.Row.Attribute s["onmouseove r"] = "javascript:Gri dViewMouseOverC olor(this);";
e.Row.Attribute s["onmouseout "] = "javascript:Gri dViewMouseOutCo lor(this);";
e.Row.Attribute s.Add("onclick" , ClientScript.Ge tPostBackEventR eference(gvDefe ctCatalog, "Select$" + e.Row.RowIndex. ToString())); }
}
HTML:
<asp:GridView ID="gvDefectCat alog" runat="server" CssClass="GridV iew"
DataKeyNames="d efectID,defectC ode"
AutoGenerateCol umns="False" OnSelectedIndex Changed="gvDefe ctCatalog_Selec tedIndexChanged "
AllowPaging="fa lse" Width="98%" ShowHeader="Fal se" ShowFooter="Fal se" EnableViewState ="true" GridLines="none " CellPadding="0" CellSpacing="0"
OnRowDataBound= "gvDefectCatalo g_RowDataBound"
OnRowCommand="g vDefectCatalog_ RowCommand"
OnRowDeleting=" gvDefectCatalog _RowDeleting"
OnRowEditing="g vDefectCatalog_ RowEditing"
OnRowCancelingE dit="gvDefectCa talog_RowCancel ingEdit"
OnRowUpdating=" gvDefectCatalog _RowUpdating">
<Columns>
<asp:TemplateFi eld>
<ItemTemplate >
<asp:Button ID="btEdit" Text="Edit" CommandName="Ed it" CausesValidatio n="false" runat="server" CssClass="GridV iewButton" Width="35px" TabIndex="14"/>
<asp:Button ID="btnDelete" Text="Delete" CommandName="De lete" runat="server" CommandArgument ='<%# Eval("defectID" ) %>' CssClass="GridV iewButton" Width="40px" TabIndex="15" OnClientClick=" return confirm('Are you sure you want to delete this data?')"/>
</ItemTemplate>
<EditItemTempla te>
<asp:Button Text="Update" CommandName="Up date" CausesValidatio n="true" runat="server" ID="btUpdate" CssClass="GridV iewButton" Width="40px" OnClientClick=" ObjectVisibilit y('UpdateProgre ss')" TabIndex="12"/>
<asp:Button Text="Cancel" CommandName="Ca ncel" CausesValidatio n="false" runat="server" ID="btECancel" CssClass="GridV iewButton" Width="40px" OnClientClick=" ObjectVisibilit y('UpdateProgre ss')" TabIndex="13"/>
</EditItemTemplat e>
<HeaderTemplate >
<asp:Button Text="Insert" CommandName="In sert" CausesValidatio n="true" runat="server" ID="btInsert" CssClass="GridV iewButton" Width="40px" OnClientClick=" ObjectVisibilit y('UpdateProgre ss')" TabIndex="12"/>
<asp:Button Text="Cancel" CommandName="Ca ncel" CausesValidatio n="false" runat="server" ID="btICancel" CssClass="GridV iewButton" Width="40px" OnClientClick=" ObjectVisibilit y('UpdateProgre ss')" TabIndex="13"/>
</HeaderTemplate>
</asp:TemplateFie ld>
<asp:CommandFie ld ButtonType="Lin k" ShowSelectButto n="true" SelectText="">
<ItemStyle Width="0%" HorizontalAlign ="left" VerticalAlign=" Middle"></ItemStyle>
</asp:CommandFiel d>
</ asp:GridView>