Private Function DidControlCausePostBack(ByVal uniqueID As StringAs Boolean

        
Dim bool As Boolean = False

        bool 
= (Not Request.Form(uniqueID) Is NothingOrElse (Not Request.Form("__EVENTTARGET"Is Nothing AndAlso Request.Form("__EVENTTARGET").Equals(uniqueID)) OrElse ((Not Request.Form(uniqueID & ".x"Is NothingAndAlso (Not Request.Form(uniqueID & ".y"Is Nothing))

        
Return bool

    
End Function
private bool DidControlCausePostBack(string uniqueID)
{

 
return (!(Request.Form[uniqueID] == null)) || (!(Request.Form["__EVENTTARGET"== null&& Request.Form["__EVENTTARGET"].Equals(uniqueID)) || ((!(Request.Form[uniqueID + ".x"== null)) && (!(Request.Form[uniqueID + ".y"== null)));
}

Protected WithEvents LinkButton1 As System.Web.UI.WebControls.LinkButton
Protected WithEvents ImageButton1 As System.Web.UI.WebControls.ImageButton
Protected WithEvents Button1 As System.Web.UI.WebControls.Button

    
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        
If DidControlCausePostBack(Button1.UniqueID) Then
            Response.Write(
"Button1")
        
End If

        
If DidControlCausePostBack(LinkButton1.UniqueID) Then
            Response.Write(
"LinkButton1")
        
End If

        
If DidControlCausePostBack(ImageButton1.UniqueID) Then
            Response.Write(
"ImageButton1")
        
End If

    
End Sub

该方法仅对Buttons, LinkButtons and ImageButtons有效
From: http://aspadvice.com/blogs/joteke/archive/2004/08/05/2288.aspx
posted on 2006-04-23 19:06  RubyPDF  阅读(1620)  评论(0编辑  收藏  举报