开发者

Declaring event in user control asp.net?

开发者 https://www.devze.com 2023-03-17 09:29 出处:网络
I have declared a event on my user control public event EventHandler<AddressEventArgs> SaveButtonClick;

I have declared a event on my user control

public event EventHandler<AddressEventArgs> SaveButtonClick; 

protected void ButtonSave_Click(object sender, EventArgs e) 
{ 
  if (SaveButtonClick != null) 
  { 
    SaveB开发者_JAVA技巧uttonClick(this, new AddressEventArgs) ; 

  } 
}

After I have added the user control to the new page, how would I trap the event raised by the user control?


Either you can [Browsable] property on the event, or you can imperatively bind to the events.

userControl.SaveButtonClick += new EventHandler(handlerFunctionName);

public void handlerFunctionName(AddressEventArgs args)
{
     // Here, you have access to args in response the the event of your user control
}


Control.SaveButtonClick += controlClicked;

protected void controlClicked(object sender, EventArgs e) 
{ 
   //Do work
}

First you need to subscribe to your event, and give it a method to call when the event is raised.

0

精彩评论

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