PRM–pageLoaded事件

PRM–pageLoaded事件
•参数类型:PageLoadedEventArgs
–dataItems属性:获得服务器端注册的数据项
–panelsCreated属性:获得新建的UpdatePanel
–panelsUpdated属性:获得已经更新的UpdatePanel
•常用操作:
–(能够)获得服务器端注册的数据项
–(能够)执行服务器端注册的脚本

局部内容添加
<% @ Page Language = " C# "  MasterPageFile = " ~/Site.master "  AutoEventWireup = " true "  CodeFile = " 4_IncrementalContent.aspx.cs "  Inherits = " _4_IncrementalContent "  Title = " IncrementalContent "  EnableViewState = " false " %>
< asp:Content ID = " Content1 "  ContentPlaceHolderID = " ContentPlaceHolder1 "  Runat = " Server " >
    
< strong > Comment: </ strong >< br  />< br  />
    
    
< div id = " commentContainer " >
        
< asp:UpdatePanel ID = " UpdatePanel1 "  runat = " server " >
            
< ContentTemplate >
                
< asp:Repeater ID = " Repeater1 "  runat = " server " >
                    
< ItemTemplate >
                        
<% # (Container.DataItem  as  Comment).Content  %>< br  />
                        
< i ><% # (Container.DataItem  as  Comment).Time  %></ i >
                        
< hr  />
                    
</ ItemTemplate >
                
</ asp:Repeater >
            
</ ContentTemplate >
            
< Triggers >
                
< asp:AsyncPostBackTrigger ControlID = " Button1 "   />
            
</ Triggers >
        
</ asp:UpdatePanel >
    
</ div >
    
    
< br  />
    
< asp:TextBox ID = " TextBox1 "  runat = " server " ></ asp:TextBox >< br  />
    
< asp:Button ID = " Button1 "  runat = " server "  Text = " Add Comment "  OnClick = " Button1_Click "   />

    
< script language = " javascript "  type = " text/javascript " >
        Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(
            function(sender, e)
            {
                var upId 
=   " <%= this.UpdatePanel1.ClientID %> " ;
                var refreshedPanels 
=  e.get_panelsUpdated();
                
                
for  (var i  =   0 ; i  <  refreshedPanels.length; i ++ )
                {
                    
if  (refreshedPanels[i].id  ==  upId)
                    {
                        refreshedPanels[i].id 
=  upId  +  Math.floor( 9999   *  Math.random());
                        var div 
=  document.createElement( " div " );
                        div.id 
=  upId;
                        $
get ( " commentContainer " ).appendChild(div);
                        
return ;
                    }
                }
            });
    
</ script >
</ asp:Content >


cs
     private   static  List < Comment >  Comments;

    
protected   void  Page_Load( object  sender, EventArgs e)
    {
        
if  ( ! this .IsPostBack)
        {
            
//  在第一次打开页面时清空所有Comments。
            
//  古怪的用法,仅在这个示例时这么用。
            Comments  =   new  List < Comment > ();
            
this .BindComments();
        }
    }

    
private   void  BindComments()
    {
        
this .Repeater1.DataSource  =  Comments;
        
this .Repeater1.DataBind();
    }

    
protected   void  Button1_Click( object  sender, EventArgs e)
    {
        Comment comment 
=   new  Comment();
        comment.Content 
=   this .TextBox1.Text;
        comment.Time 
=  DateTime.Now;

        
//  Comments.Add(comment);
         this .Repeater1.DataSource  =   new  Comment[] { comment };
        
//  this.BindComments();
         this .Repeater1.DataBind();
    }

你可能感兴趣的:(load)