Thread: C# основной форум/Set OnClientClick programmatically

Set OnClientClick programmatically
click

public static Control FindControl(string controlID, ControlCollection
controls)
{
   foreach (Control control in controls)
   {
       if(control.ID == controlID)
           return control;

       if(control.HasControls())
       {
           Control nestedControl = FindControl(controlID, control.Controls);

           if(nestedControl != null)  
               return nestedControl;
       }
   }
   return null;
}

//Then, supposing the control's ID is FinishButton1, I use it this way:

Button finishCompleteButton = (Button)FindControl("FinishButton1",
Page.Controls);

string serverSidePropertyValue = "alert('hello');";

finishCompleteButton.Attributes.Add("onclick", serverSidePropertyValue);

// this way I'm not forced to assign a static value to the client-side
onclick event handler as I would do with "OnClientClick" property.