页面开发技巧 asp.net控件事件 以维持滚动位置 客户端回调

1、提交后的回发时能自动进入上次的当前位置

例如,如果数据项导致大型页回发,则最终用户需要将页滚动到此前正在编辑它们的位置,才能继续。页开发人员通过以下方法可以简单地标记窗体,以维持滚动位置:在 @Page 指令中将 MaintainScrollPositionOnPostBack 属性设置为 true,或在 Web.config 中进行此设置,以应用于应用程序中的所有页。

2、Button 控件的 OnClientClick 属性允许您在此按钮被单击时以编程方式运行客户端脚本。该按钮呈现客户端 onclick 属性以及按钮自身的 Javascript。

3、用于控件的一个令人惊喜的新功能是“客户端回调”,该功能允许控件向服务器执行带外请求以获取附加数据,而不发送整页。此功能依赖于用于回调处理(通常通过 XMLHTTP)的浏览器支持,该支持由 SupportsClientCallbacks 在浏览器功能中指定。

其实一般的无刷新页面就可以使用客户端回调来实现,只有复杂的才需要使用AJAX等

<% @ Page Language = " C# "  AutoEventWireup = " true "  EnableEventValidation = " false "  CodeFile = " CallBackEventHandler_cs.aspx.cs "  Inherits = " CallBackEventHandler_cs "   %>

<! DOCTYPE html PUBLIC  " -//W3C//DTD XHTML 1.0 Transitional//EN "   " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd " >

< html xmlns = " http://www.w3.org/1999/xhtml "   >
< head runat = " server " >
   
< title > Client CallBack </ title >
</ head >
< body >
< form id = " Form1 "  runat = " server " >

   
< h3 > Cascading DropDownLists Using ICallBackEventHandler </ h3 >
   
< asp:DropDownList ID = " ParentDropDown "
    onchange
= " GetChildren(this.options[this.selectedIndex].value, 'ddl'); "    
    Runat
= " server " >
     
< asp:ListItem Text = " Item 1 "   />
     
< asp:ListItem Text = " Item 2 "   />
     
< asp:ListItem Text = " Item 3 "   />
   
</ asp:DropDownList >
   
< asp:DropDownList ID = " ChildDropDown "  AutoPostBack = " true "  style = " visibility:hidden "  Runat = " Server " >
    
< asp:ListItem Text = " Child Item "   />
   
</ asp:DropDownList >
   
< br  />< br  />
   
< asp:Label ID = " Label1 "  runat = " server " />

   
< script type = " text/javascript " >

   function ClientCallback(result, context)
{

      var childDropDown 
= document.forms[0].elements['<%=ChildDropDown.UniqueID%>'];

      
if (!childDropDown){
         
return;
      }


      childDropDown.length 
= 0;

      
if (!result){
          
return;
      }

      
      var rows 
= result.split('|'); 
      
for (var i = 0; i < rows.length; ++i){
         var option 
= document.createElement("OPTION");
         option.value 
= rows[i];
         option.innerHTML 
= rows[i];     
         childDropDown.appendChild(option);
      }

      
      childDropDown.style.visibility 
= "visible";
   }


   function ClientCallbackError(result, context)
{
      alert(result);
   }


   
</ script >

</ form >
</ body >

</ html >

 

 

 

 

 

 

source http://www.cnblogs.com/firstyi/archive/2006/11/13/559156.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值