The event loading of ASP. NET Web control buttons is invalid.

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.