之前發過用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
<script type="text/javascript">
<!--
function initializeServerSide()
{
// Get the value to return here
var eventArgument = 'Some value to send server-side';
__doPostBack('initializeServerSidePostBack', eventArgument)
}
// -->
</script>