我正在使用asp.net c#设计Web应用程序。我正在使用gridview控件。
在gridview中,我有添加,编辑和删除按钮
我有一个问题是任何人都知道当用户按下取消或更新或删除按钮然后按钮将显示并询问“你想更新记录”并且选项是YES而否如果用户按是然后只记录保存其他明智取消。
**
*****> At the time of user press "Cancel
> Update" i want to check if any data is
> changed give message "Data is changed
> Do you want to cancel it" Yes or no if
> press yes then cancel other wise stay
> there.. how it's possible becz is ajax
> extender ask all time the time*****
**
在网络应用程序中如何实现?
由于
答案 0 :(得分:1)
您可以使用Ajax ASP.NET扩展程序进行按钮确认。
<TemplateColumn>
<ItemTemplate>
<asp:LinkButton id="lbDelete" runat="server" CommandName="Delete" Text="Delete"/>
<cc1:ConfirmButtonExtender ID="cbeDelete" runat="server"
ConfirmText="Are you sure you want to delete this record?"
TargetControlID="lbDelete" />
</ItemTemplate>
<ItemTemplate>
<asp:LinkButton id="lbCancelUpdate" runat="server" CommandName="Cancel" Text="Cancel"/>
<cc1:ConfirmButtonExtender ID="cbeCancel" runat="server"
ConfirmText="Are you sure you want to cancel any changes?"
TargetControlID="lbCancelUpdate" />
</ItemTemplate>
</TemplateColumn>
答案 1 :(得分:1)
我通过扩展Button控件采取略微不同的方法。只是更一般的目的。
<bo:LinkButton id="Button1" runat="server" ConfirmText="Delete?" />
public class LinkButton : System.Web.UI.WebControls.LinkButton
{
[Bindable(true), Category("Behavior"), DefaultValue("")]
public string AlertText
{
get { return (string)ViewState["AlertText"] ?? string.Empty; }
set { ViewState["AlertText"] = value; }
}
[Bindable(true), Category("Behavior"), DefaultValue("")]
public string ConfirmText
{
get { return (string)ViewState["ConfirmText"] ?? string.Empty; }
set { ViewState["ConfirmText"] = value; }
}
protected override void CreateChildControls()
{
string script = string.Empty;
if (AlertText.Length > 0)
{
script += string.Format("alert('{0}');", AlertText);
}
if (ConfirmText.Length > 0)
{
script += string.Format("return confirm('{0}');", ConfirmText);
}
if (script.Length > 0)
{
OnClientClick = script;
}
base.CreateChildControls();
}
}
答案 2 :(得分:0)
在这些按钮的客户端脚本中,您想要执行类似
的操作if (confirm('Are you sure you want to delete this item'))
{
//Do logic for delete item
}
把它放在你电脑上的.html文件中并在浏览器中打开它(如果你的ie7你会得到安全警告只是允许它,从网址启动时不会发生这种情况):
<html>
<body>
<script>
if (confirm('You want to delete me?')
{
alert('deleted');
}
</script>
</body>
</html>
确认是一个功能; - )