1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
|
[PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
public class GenericButton : WebControl, IButtonControl, IPostBackEventHandler
{
public event EventHandler Click;
[...]
protected override void AddAttributesToRender(HtmlTextWriter writer)
{
if (Page != null)
Page.VerifyRenderingInServerForm(this);
PostBackOptions postBackOptions = GetPostBackOptions();
if ((UniqueID != null) && ((postBackOptions == null) || (postBackOptions.TargetControl == this)))
writer.AddAttribute(HtmlTextWriterAttribute.Name, UniqueID);
writer.AddAttribute(HtmlTextWriterAttribute.Onclick, Page.ClientScript.GetPostBackEventReference(postBackOptions, true));
[...]
base.AddAttributesToRender(writer);
}
protected virtual PostBackOptions GetPostBackOptions()
{
PostBackOptions options = new PostBackOptions(this, String.Empty);
if (!String.IsNullOrEmpty(PostBackUrl))
options.ActionUrl = HttpUtility.UrlPathEncode(ResolveClientUrl(PostBackUrl));
if ((CausesValidation && (Page != null)) && (Page.GetValidators(ValidationGroup).Count > 0))
{
options.PerformValidation = true;
options.ValidationGroup = ValidationGroup;
}
options.ClientSubmit = !UseSubmitBehavior;
return options;
}
protected virtual void OnClick(EventArgs e)
{
if (Click != null)
Click(this, e);
}
[...]
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
if (Page != null)
Page.RegisterRequiresRaiseEvent(this);
}
public void RaisePostBackEvent(string eventArgument)
{
if (Page != null)
Page.ClientScript.ValidateEvent(UniqueID, eventArgument);
[...]
OnClick(EventArgs.Empty);
[...]
}
[...]
} |
Partager