如果使用javascript启用linkbutton false,如何删除确认消息 [英] How to remove confirmation message if linkbutton is enable false with javascript
问题描述
我在gridview中有一个删除链接按钮,当用户点击按钮时有确认消息。但是当我的按钮被禁用时有一些条件,我想要在我的按钮被禁用时不显示确认框。
我的java脚本功能是
i have a delete linkbutton inside gridview and there are confirm message while user click on button. but there are some condition when my button disable and i want do not show confirmation box when my button is disable.
my java script function is
function DeleteConfirmation()
{
if (confirm("Are you sure,you want to delete selected record ?")==true)
return true;
else
return false;
}
我的gridview
my gridview
<asp:GridView ID="grdShowProduct" runat="server"
AutoGenerateColumns="false" onrowcommand="grdShowProduct_RowCommand"
onrowdatabound="grdShowProduct_RowDataBound" Width="100%"
AutoGenerateEditButton="true" AutoGenerateDeleteButton="false"
onrowcancelingedit="grdShowProduct_RowCancelingEdit"
onrowediting="grdShowProduct_RowEditing"
onrowupdating="grdShowProduct_RowUpdating" >
<HeaderStyle CssClass="headerGrd" />
<AlternatingRowStyle CssClass="alternateRowGrd" />
<EditRowStyle CssClass="editGrd" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkDelete" OnClientClick="return DeleteConfirmation();" Text="Delete" CommandName="Remove" CommandArgument='<%# Bind("id") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="lnkMoreDetail" CssClass="MoreDetail" Text="Lots Detail" CommandName="show" CommandArgument='<%# Bind("id") %>' runat="server" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="lnkMoreDetail" CssClass="MoreDetail" Text="Lots Detail" CommandName="show" CommandArgument='<%# Bind("id") %>' runat="server" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Date" >
<ItemTemplate>
<asp:Label ID="lblId" Text='<%# Bind("id") %>' Visible="false" runat="server" />
<asp:Label ID="lblGrdDate" runat="server" Text='<%# Eval("date","{0:dd-MMM-yyyy}") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Order Code" >
<ItemTemplate>
<asp:Label ID="lblGrdOrderCode" runat="server" Text='<%# Bind("orderCode") %>' ClientIDMode="Static" ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtGrdOrderCode" Text='<%# Bind("orderCode") %>' />
<asp:FilteredTextBoxExtender ID="fltGrdOrderCode1" FilterType="UppercaseLetters, LowercaseLetters, Custom" TargetControlID="txtGrdOrderCode" ValidChars=" -" runat="server" />
<asp:RequiredFieldValidator ID="reqGrdOrderCode1" ControlToValidate="txtGrdOrderCode" CssClass="validationError" runat="server" Display="Dynamic" ErrorMessage="Order Code cannot be empty." ValidationGroup="Update">*</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Color" >
<ItemTemplate>
<asp:Label ID="lblGrdColor" runat="server" Text='<%# Bind("color") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblGrdColor" runat="server" Text='<%# Bind("color") %>' Visible="false" ></asp:Label>
<%--<asp:Label ID="lblColorId" Text='<%# Bind("colorId") %>' Visible="false" runat="server" ClientIDMode="Static" />--%>
<asp:DropDownList ID="ddlColor1" runat="server" Width="175px" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="reqColorShw" ControlToValidate="ddlColor1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity" >
<ItemTemplate>
<asp:Label ID="lblGrdQuantity" runat="server" Text='<%# Bind("quantity") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtQuantity1" runat="server" Text='<%# Bind("quantity") %>' BorderStyle="none" BorderWidth="0px"></asp:TextBox>
<asp:FilteredTextBoxExtender ID="fltQuantityShw" FilterType="Numbers" TargetControlID="txtQuantity1" runat="server" />
<asp:RequiredFieldValidator ID="reqQuantityShw" ControlToValidate="txtQuantity1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Quantity per Lot" >
<ItemTemplate>
<asp:Label ID="lblGrdQuantityPrLot" runat="server" Text='<%# Bind("quantityPrLot") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtQuantityPrLot1" runat="server" Text='<%# Bind("quantityPrLot") %>' BorderStyle="none" CssClass="QuntLot" BorderWidth="0px" ></asp:TextBox>
<asp:FilteredTextBoxExtender ID="fltQuantityPrLotShw" FilterType="Numbers" TargetControlID="txtQuantityPrLot1" runat="server" />
<asp:RequiredFieldValidator ID="reqQuantityPrLotShw" ControlToValidate="txtQuantityPrLot1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Total Lots">
<ItemTemplate>
<asp:Label ID="txtTotalLots1" runat="server" Text='<%# Bind("totalLots") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Origin" >
<ItemTemplate>
<asp:Label ID="lblGrdOrigin" runat="server" Text='<%# Bind("origin") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblGrdOrigin" runat="server" Text='<%# Bind("origin") %>' Visible="false"></asp:Label>
<%-- <asp:Label ID="lblOriginId" Text='<%# Bind("OriginId") %>' Visible="false" runat="server" />--%>
<asp:DropDownList ID="ddlOrigin1" runat="server" Width="175px" ></asp:DropDownList>
<asp:RequiredFieldValidator ID="reqOriginShw" ControlToValidate="ddlOrigin1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Grade" >
<ItemTemplate>
<asp:Label ID="lblGrdGrade" runat="server" Text='<%# Bind("gradeId") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblGrdGrade" runat="server" Text='<%# Bind("gradeId") %>' Visible="false" ></asp:Label>
<asp:DropDownList ID="ddlGrade1" runat="server" Width="175px" >
<asp:ListItem Value="0" Text="Select Grade"></asp:ListItem>
<asp:ListItem Value="1" Text="1"></asp:ListItem>
<asp:ListItem Value="2" Text="2"></asp:ListItem>
<asp:ListItem Value="3" Text="3"></asp:ListItem>
<asp:ListItem Value="4" Text="4"></asp:ListItem>
<asp:ListItem Value="5" Text="5"></asp:ListItem>
<asp:ListItem Value="6" Text="6"></asp:ListItem>
<asp:ListItem Value="7" Text="7"></asp:ListItem>
<asp:ListItem Value="8" Text="8"></asp:ListItem>
<asp:ListItem Value="9" Text="9"></asp:ListItem>
<asp:ListItem Value="10" Text="10"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqGradeShw" ControlToValidate="ddlGrade1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D.M." >
<ItemTemplate>
<asp:Label ID="lblGrdDM" runat="server" Text='<%# Bind("DM") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txtDM1" runat="server" Text='<%# Bind("DM") %>' BorderStyle="none" BorderWidth="0px"></asp:TextBox>
<asp:FilteredTextBoxExtender ID="fltDMShw" FilterType="Numbers" TargetControlID="txtDM1" runat="server" />
<asp:RequiredFieldValidator ID="reqDMShw" ControlToValidate="txtDM1" CssClass="validationError" runat="server" Display="Dynamic" Text="*" ErrorMessage="*" ValidationGroup="Update"></asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Process" >
<ItemTemplate>
<asp:Label ID="lblGrdProcess" runat="server" Text='<%# Bind("IsManual") %>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblGrdProcess" runat="server" Text='<%# Bind("IsManual") %>' Visible="false" ></asp:Label>
<asp:DropDownList ID="ddlProcess1" runat="server" >
<asp:ListItem Value="-1" Text="Select Process"></asp:ListItem>
<asp:ListItem Value="0" Text="Manual"></asp:ListItem>
<asp:ListItem Value="1" Text="Standard"></asp:ListItem>
</asp:DropDownList>
<asp:RequiredFieldValidator ID="reqProcessShw" ControlToValidate="ddlProcess1" InitialValue="-1" runat="server" CssClass="validationError" Display="Dynamic" Text="Please,Select any process." ErrorMessage="Please,Select any process." ValidationGroup="Update">*</asp:RequiredFieldValidator>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Status" >
<ItemTemplate>
<asp:Label ID="lblGrdStatus" runat="server" Text='<%# Bind("IsCompleted") %>' ></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
when Status field is Waiting my button will be enable else button will be disable
c# code
gridview rowdataboud code
LinkButton lnkDelete = (LinkButton)e.Row.FindControl(\"lnkDelete\");
if (lblGrdStatus.Text != \"Waiting\")
{
lnkDelete.Enabled = false;
}
please tell me how to solve this problem
thanks in advance
when Status field is Waiting my button will be enable else button will be disable
c# code
gridview rowdataboud code
LinkButton lnkDelete = (LinkButton)e.Row.FindControl("lnkDelete");
if (lblGrdStatus.Text != "Waiting")
{
lnkDelete.Enabled = false;
}
please tell me how to solve this problem
thanks in advance
推荐答案
Add below code with your code at code behind hope it will work
Add below code with your code at code behind hope it will work
LinkButton lnkDelete = (LinkButton)e.Row.FindControl("lnkDelete");
if (lblGrdStatus.Text != "Waiting")
{
lnkDelete.Enabled = false;
LinkButton1.OnClientClick = "return false;";
}
In asp:linkbutton if it is disable then it wil apply this
In asp:linkbutton if it is disable then it wil apply this
class="aspNetDisabled"
. so you just need to check on that javascript click function that clicked source is have this class attach or not?. this will solve your problem.
. so you just need to check on that javascript click function that clicked source is have this class attach or not?. this will solve your problem.
这篇关于如果使用javascript启用linkbutton false,如何删除确认消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!