惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

L
LINUX DO - 热门话题
Engineering at Meta
Engineering at Meta
GbyAI
GbyAI
Microsoft Security Blog
Microsoft Security Blog
月光博客
月光博客
Jina AI
Jina AI
博客园_首页
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
博客园 - 司徒正美
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
腾讯CDC
Recorded Future
Recorded Future
大猫的无限游戏
大猫的无限游戏
G
Google Developers Blog
D
Docker
罗磊的独立博客
美团技术团队
爱范儿
爱范儿
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
云风的 BLOG
云风的 BLOG
宝玉的分享
宝玉的分享
J
Java Code Geeks
U
Unit 42
Hugging Face - Blog
Hugging Face - Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
SecWiki News
SecWiki News
T
Troy Hunt's Blog
H
Heimdal Security Blog
The Cloudflare Blog
Webroot Blog
Webroot Blog
aimingoo的专栏
aimingoo的专栏
Security Archives - TechRepublic
Security Archives - TechRepublic
F
Full Disclosure
AI
AI
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Last Week in AI
Last Week in AI
T
The Exploit Database - CXSecurity.com
V
V2EX
Spread Privacy
Spread Privacy
M
MIT News - Artificial intelligence
量子位
Y
Y Combinator Blog
阮一峰的网络日志
阮一峰的网络日志
NISL@THU
NISL@THU
Hacker News: Ask HN
Hacker News: Ask HN
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
N
News and Events Feed by Topic
Attack and Defense Labs
Attack and Defense Labs

博客园 - jerreychen

常用的JavaScript验证正则表达式 用CSS设置打印换页 使用Form认证实现用户登录 (LoginView的使用) 向容器(PlaceHolder)中动态添加多个用户控件(UserControl) C#.Net中WinForm采用Active Directory进行身份认证 Windows XP 如何设置系统自动关机任务 - jerreychen DataList嵌套GridView实现文章分类列表显示(2) visual studio 2008 sp1中如何让WebBrowser控件可编辑 - jerreychen SQLite 数据库初学 学习笔记 - jerreychen - 博客园 如何将.xsd文件自动生成对象 ASP.NET页面事件:顺序与回传详解 读取自定义的config文件 - jerreychen - 博客园 Umbraco 设置Document Types 的默认值 格式化数据 Net支持gzip 压缩格式 压缩与解压 .net 序列化数据对象 .net 下,日期的格式化 太久太久没来了,久违了-博客园
showModelDialog 关闭后改变GridView某个单元格的值
jerreychen · 2007-12-11 · via 博客园 - jerreychen

.net Ajax 是一个非常不错的东西 方便的实现了B/S的异步数据传输,我们只需要在页开始加入

<asp:ScriptManager runat="server" ID="scriptManager"></asp:ScriptManager>

然后在需要用到异步传输的地方加上<UpdatePanel...></UpdatePanel> 经过简单设置,OK,一个ajax就完成了

但是当.net ajax有一个非常不好的地方,就是传输数据是整个页面的,数据量很大,网络不好的时候,就感觉很慢
我们的页面中有一个GridView,浏览这个页面时候,浏览器向服务器发送一个请求;
然后从服务器下载数据到本地;
接着我们按了某个按钮触发PostBack事件;
于是这个页面的GridView的数据又重新绑定,重新下载了一遍
但是很多时候我们只需要GridView中的部分内容改动就够了,所以整个GridView传输是没有必要的
这个时候我们可以用客户端的Javascript脚本实现对GridView中某个单元格的更改

比如我们的GridView中的ItemTemplate列里有一个按钮,一般我们都直接设置一下它的CommandName和CommandArgument进行服务器端操作的
这里我们可以把它做成客户端按钮Input,然后对它添加Onclick事件,showModelDialog出页面,让在服务器端执行的脚本在那个页面中执行
接着在关闭showModelDialog的时候,更改页面中GridView的某个对应的单元格的值

GridView解析到页面Html时候,它是一个XML格式的HTML文本,我们用Javascript脚本可以按照找节点(Node)的方式去实现找到某个单元格
下面是一个例子,这里我用A链接实现,如果是input也是一样的


                            
<asp:TemplateField HeaderText="Action">
                                
<ItemTemplate>
                                
<div style="text-align:center">
                                    
<href='editCampaign.aspx?campaignID=<%# Eval("campaignID") %>' class="CommonTextButton">
                                        Edit
</a>
                                    
<href='javascript:void(0);' onclick="ShowTestDialog('runCampaign.aspx?CampaignID=<%# Eval("campaignID") %>&action=testRun','testRun',this);" class="CommonTextButton">
                                        Test
</a>
                                    
<href='javascript:void(0);' onclick="ShowTestDialog('runCampaign.aspx?CampaignID=<%# Eval("campaignID") %>&action=releaseRun','releaseRun',this);" class="CommonTextButton">
                                        Release
</a>
                                    
<href='javascript:void(0);' onclick="ShowTestDialog('runCampaign.aspx?CampaignID=<%# Eval("campaignID") %>&action=releaseDebugRun','releaseDebugRun',this);" class="CommonTextButton">
                                        Debug Release
</a>
                                
</div>
                                
</ItemTemplate>
                            
</asp:TemplateField>


这里a链接的href设为 javascript:void(0); 这是让页面不会跳 如果我们用#如果页面比较长,就会跳到页首的

                   <script language="javascript" type="text/javascript">
                   
function ShowTestDialog(url,type,sender)
                   
{
                       
if(type == "testRun")
                       
{
                            window.showModalDialog(url,'v','dialogWidth:500px;dialogHeight:100px;status:
0;help:0');
                            sender.parentNode.parentNode.parentNode.childNodes[
3].innerHTML=Date();
                       }

                       
else if(type == "releaseRun")
                       
{
                            
var arr = window.showModalDialog(url,'w','dialogWidth:500px;dialogHeight:100px;status:0;help:0');
                            sender.parentNode.parentNode.parentNode.childNodes[
4].innerHTML=Date();
                       }

                       
else
                       
{
                            window.showModalDialog(url,'x','dialogWidth:500px;dialogHeight:115px;status:
0;help:0');
                       }

                       
                   }

                   
</script>


runCampaign.aspx中是事件处理的方法,页面的head里面需要简单设置下

<head runat="server">
    
<title>Run Campaign</title>
    
<base target="_self" />
</head>