如题,我想取鼠标点击的那个控件的ID....知道的请告诉我.谢谢,最好有代码

解决方案 »

  1.   

    客户端控件还是服务器端控?
    js:
    event.srcElement
    服务器:
    ((Control)sender).ID
      

  2.   

    // js
    var id = event.srcElement.id;// cs
    ... Button1_Click(object sender, ...
    {
        string id = (sender as Control).ID
    }
      

  3.   

    服务端  public static Control FindThePostBackControl(Control container)
            {
                // Note: this is an adapted eggheadcafe.com code.
                //
                Control control = null;            string ctrlname = HttpContext.Current.Request.Params["__EVENTTARGET"];
                if ( ctrlname != null && ctrlname != String.Empty )
                {
                    string[] tokens = ctrlname.Split( new char[1] { ':' } );                if ( tokens != null && tokens.GetLength( 0 ) > 0 )
                    {
                        ctrlname = tokens[( tokens.GetLength( 0 ) - 1 )];
                    }                control = container.FindControl( ctrlname );
                }
                else
                {
                    // If __EVENTTARGET is null, control is a button type and need to 
                    // iterate over the form collection to find it
                    //
                    string ctrlStr = String.Empty;
                    Control c = null;
                    foreach ( string ctl in HttpContext.Current.Request.Form )
                    {                    // Handle ImageButton controls
                        if ( ctl.EndsWith( ".x" ) || ctl.EndsWith( ".y" ) )
                        {
                            ctrlStr = ctl.Substring( 0 , ( ctl.Length - 2 ) );
                            c = container.FindControl( ctrlStr );
                        }
                        else
                        {
                            c = container.FindControl( ctl );
                        }                    if ( c is System.Web.UI.WebControls.Button || c is System.Web.UI.WebControls.ImageButton )
                        {
                            control = c;
                            break;
                        }
                    }
                }            return control;
            }
      

  4.   

    又见孟子
    学习js:
    event.srcElement
    服务器:
    ((Control)sender).ID