用__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( this string .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

 

 

你可能感兴趣的:(JavaScript)