ASP. NET has not been used for a long time, and the work needs to be picked up again. Create a toolbar and add the operation button dynamically.
/// <Summary>
/// Initialization structure
/// </Summary>
Public TKToolBar ()
{
BtnExprot = new Button ();
BtnExprot. CommandName = BTN_EXPORT;
BtnExprot. CssClass = "btn_dc ";
BtnExprot. Click + = new EventHandler (btn_Click );
}
/// Process button events in a unified manner
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "e"> </param>
Void btn_Click (object sender, EventArgs e)
{
Button btn = sender as Button;
If (btn. CommandName = BTN_EXPORT)
{
If (OnExportClick! = Null)
{
OnExportClick (sender, e );
}
}
}
/// <Summary>
/// Control rendering
/// </Summary>
/// <Param name = "writer"> </param>
Protected override void Render (HtmlTextWriter writer)
{
Writer. write ("<table width = \" "+ this. width + "\" border = \ "0 \" cellspace = \ "0 \" cellpadding = \ "0 \"> <tr> <td align = \ "right \"> ");
// Export button
If (! String. IsNullOrEmpty (ButtonExportScript ))
{
BtnExprot. OnClientClick = ButtonExportScript;
}
If (ButtonExport &&(! RightCtrl | (RightCtrl & PermissionRight. ExportEnable )))
{
BtnExprot. RenderControl (writer );
}
}
The above code is displayed normally during execution, but the server button event is invalid and depressing.
After a long time, the button control was not added to the control set,
This. Controls. Add (btnExprot); is missing.
Modify
/// <Summary>
/// Initialization structure
/// </Summary>
Public TKToolBar ()
{
BtnExprot = new Button ();
BtnExprot. CommandName = BTN_EXPORT;
BtnExprot. CssClass = "btn_dc ";
BtnExprot. Click + = new EventHandler (btn_Click );
This. Controls. Add (btnExprot );
}
The reason is that, although buttons are displayed, the events of the buttons cannot bubble up because the control tree does not build the relationship between them.
This is a low-level mistake.
From YSH's column