开发者

Copy Event To Cloned Contorl

开发者 https://www.devze.com 2023-02-11 05:42 出处:网络
i have this method in asp.net for clo开发者_开发技巧ne my control : public static Control Clone( Control ctrlSource )

i have this method in asp.net for clo开发者_开发技巧ne my control :

public static Control Clone( Control ctrlSource )
{
    Type t = ctrlSource.GetType();
    Control ctrlDest = ( Control )t.InvokeMember( "" , BindingFlags.CreateInstance , null , null , null );
    foreach( PropertyInfo prop in t.GetProperties() )
    {
       if( prop.CanWrite )
       {
          if( prop.Name == "ID" )
          {
              ctrlDest.ID = ctrlSource.ID + "cloned" + Security.Cryptography.Cryptography.generateRandomPrivateKey( 5 );
          }
          else
          {
              prop.SetValue( ctrlDest , prop.GetValue( ctrlSource , null ) , null );
          }
       }
    }      
    return ctrlDest;

}

how can i set the source control event(like Click event) in destination control?


There is no way you can get a list of methods (AKA Invocation List) subscribed to an event using reflection. You can subscribe or unsubscribe, but cannot get a list of all methods. Every control (or type) can implement it differently.

Why not explain why you want to do that and someone can suggest another way to do that.

0

精彩评论

暂无评论...
验证码 换一张
取 消