Hi,
You have To write it on pageLoad event

ButtonName.Attributes.Add("OnClick","Sample()")