asp.net学习笔记

1. %=和%#的区别

%=表示从后台获取数据,而%#也是从后台获取数据,不过它的数据必须DataBind后才生效

2. 设置焦点

 
 
  
  usernameTextBox.Focus();
 
 

3. 服务器端构造JS代码的一种方法

 
 
  
  RaiseCallbackEvent,处理从页面上的JS脚本传递过来的请求和数据,处理后,再将结果传回给页面。
  
  
GetPostBackEventReference,获取对客户端脚本函数的引用,调用该函数将使服务器发送回该页。该方法还将一个参数传递到在服务器上执行回发处理的服务器控件。 (Page.GetPostBackEventReference(Button1,"inc") == "__doPostBack('Button1','inc')", Button1是Button1的ID)
 
 
  
  范例1:

  
  
public   class  MyControl : Control, IPostBackEventHandler
{
   
public void RaisePostBackEvent(string eventArgument)
   
{
     
if ( eventArgument == "inc" )
     Number 
= Number + 1;

     
if ( eventArgument == "dec" )
     Number 
= Number - 1;
   }

   
[System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name
="FullTrust")]
   
protected override void Render(HtmlTextWriter writer)
   
{
     writer.Write(
"The Number is " + Number.ToString() + " (" );
     writer.Write(
"<a href="javascript:" + Page.GetPostBackEventReference(this,"inc"+ "">Increase Number</a>"); 
     writer.Write(
" or ");
     writer.Write(
"<a href="javascript:" + Page.GetPostBackEventReference(this,"dec"+ "">Decrease Number</a>");
   }

}
范例2:绑定控件的ENTER事件到特定控件上

public   static   void  TieButton(Page page, Control TextBoxToTie, Control ButtonToTie)                                                                                                                     
{
  
string jsString = "";
  
if ((ButtonToTie is LinkButton) || (ButtonToTie is ImageButton))
  
{
      jsString 
= "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {"
               
+ page.ClientScript.GetPostBackEventReference(ButtonToTie, "").Replace(":""$")
               
+ ";return false;} else return true;";
  }

  
else
  
{
      jsString 
= "if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {document."
             
+ "forms[0].elements['" + ButtonToTie.UniqueID.Replace(":""_")
             
+ "'].click();return false;} else return true; ";
  }

  
// Attach jscript to the onkeydown attribute—we have to cater for HtmlControl or WebControl
  if (TextBoxToTie is HtmlControl)
  
{
  ((HtmlControl)TextBoxToTie).Attributes.Add(
"onkeydown", jsString);
  }

  
else if (TextBoxToTie is WebControl)
  
{
  ((WebControl)TextBoxToTie).Attributes.Add(
"onkeydown", jsString);
  }

}

4. 页面构造时控件初始化顺序

Master Page child controls initialization.
Content Page child controls initialization.
Master page initialization.
Content Page initialization.
Content Page load.
Master Page load.
Master Page child controls load.
Content Page child controls load.

5. HttpApplication常用事件顺序


BeginRequest 在 ASP.NET 响应请求时作为 HTTP 执行管线链中的第一个事件发生
AuthenticateRequest 当安全模块已建立用户标识时发生。
AuthorizeRequest 当安全模块已验证用户授权时发生。
IHttpModule进行URL重写请在你关注的阶段注册相应事件,如
public void Init(HttpApplication application)
{
 application.AuthorizeRequest += new EventHandler(this.Application_AuthorizeRequest);
}
 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值