用__postback传递JavaScript变量到c#(pass a js variable to C# by a __postback )

之前发过用POST方式的http://www.cnblogs.com/blodfox777/articles/1271912.html

而用__postback比较高阶,代码出自NC01

 

 

private void Page_Load(object sender, System.EventArgs e)
{
 
// Insure that the __doPostBack() JavaScript method is created
 this.GetPostBackEventReference(thisstring.Empty);

 
if ( this.IsPostBack )
 {
  
string eventTarget = (this.Request["__EVENTTARGET"== null? string.Empty : this.Request["__EVENTTARGET"];
  
string eventArgument = (this.Request["__EVENTARGUMENT"== null? string.Empty : this.Request["__EVENTARGUMENT"];

  
if ( eventTarget == "initializeServerSidePostBack" )
  {
   
string valueSent = eventArgument;
  }
 }
 
else
 {
  ClientScript.RegisterStartupScript(GetType(Page), 
"initializeServerSideScript""initializeServerSide();"true)
 }
}

 

 

Code

 

 

posted @ 2008-08-26 09:30  LanceZhang  阅读(924)  评论(0编辑  收藏  举报