Rendering the provided string value to the client side is the main purpose of this code snippet.
public partial class AwsomeUserControl : System.Web.UI.UserControl
{
public string OnClientClick { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Page_PreRender(object sender, EventArgs e)
{
if (!string.IsNullOrWhiteSpace(OnClientClick))
{
ScriptManager.RegisterStartupScript(this, GetType(), "script",
OnClientClick, true);
}
}
}
But the actual functionality of ASP.Net Button control's OnClientClick event goes beyond this simple rendering. For a more in-depth understanding, Resharper or decompile tools can be used.
Below is the detailed source code -
/// Adds the attributes of the <see cref="T:System.Web.UI.WebControls.Button"/> control to the output stream for rendering on the client.
/// </summary>
/// <param name="writer">An <see cref="T:System.Web.UI.HtmlTextWriter"/> that contains the output stream to render on the client. </param>
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
// Code snippet for adding attributes and rendering process
}