关键词:Jquery,asp.net 2.0 ,数据控件
主要功能,简化代码,实现在删除功能之前弹出对话框提示。
asp.net2.0 数据控件中,很多都有删除功能的, 通常我们在删除操作之前都会提示用户。按照以前的方式,我们是在控件LinkButton 之前写上自定义的属性OnClick,现在有了jQuery,我可以这样实现。代码只支持LinkButton删除方式,还不支持Button!
/// <summary>
/// 操作时弹出对话框,需要Jquery支持
/// </summary>
/// <param name="message"></param>
/// <param name="hreftext"></param>
public static void ConfirmCommandMessageUseJquery(Page page,string message, string commandType)
{
string js = "$(document).ready(function(){ var arr = $(\"a\"); arr.each(function(){ var s = this.href; if(s.indexOf(\"" + commandType + "\")!=-1) { $(this).click(function(){ return confirm('" + message + "'); });} }); });";
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
ClientScriptManager cs = page.ClientScript;
if (!cs.IsStartupScriptRegistered("jqueryDelete"))
{
cs.RegisterStartupScript(typeof(Page), "jqueryDelete", js, true);
}
}
protected void Page_Load(object sender, EventArgs e)
{
ClientScriptManager cs = Page.ClientScript;
if (!cs.IsClientScriptIncludeRegistered(typeof(Page), "jquery")) //注册jquery
{
cs.RegisterClientScriptInclude(typeof(Page), "jquery", ResolveUrl("~/js/jquery.js"));
}
}
页面调用
JScript.ConfirmCommandMessageUseJquery(this, "确定删除用户,删除用户会删除用户其他相关的记录,请小心操作!", "Delete");
关于Jquery的使用,请浏览官方网站
www.jquery.com
主要功能,简化代码,实现在删除功能之前弹出对话框提示。
asp.net2.0 数据控件中,很多都有删除功能的, 通常我们在删除操作之前都会提示用户。按照以前的方式,我们是在控件LinkButton 之前写上自定义的属性OnClick,现在有了jQuery,我可以这样实现。代码只支持LinkButton删除方式,还不支持Button!
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockStart.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/InBlock.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedSubBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/ExpandedBlockEnd.gif)
![](https://www.cnblogs.com/Images/OutliningIndicators/None.gif)
关于Jquery的使用,请浏览官方网站
www.jquery.com