/// <summary> /// Creates a button. /// </summary> /// <param name="style">The style.</param> /// <param name="displaySetup"></param> /// <param name="behavior">The behavior. Pass null to use the form default action. If you need to add additional JavaScript action statements to any /// behavior besides <see cref="CustomButtonBehavior"/>, we recommend using the jQuery document ready event to add an additional click handler to the /// appropriate button element(s), which you can select using a class if there is no simpler way.</param> /// <param name="classes">The classes on the button.</param> public EwfButton(ButtonStyle style, DisplaySetup displaySetup = null, ButtonBehavior behavior = null, ElementClassSet classes = null) { behavior = behavior ?? new FormActionBehavior(FormState.Current.DefaultAction); var elementChildren = style.GetChildren(); var elementEtherealChildren = behavior.GetEtherealChildren(); children = new DisplayableElement( context => { behavior.AddPostBack(); return(new DisplayableElementData( displaySetup, () => new DisplayableElementLocalData( "button", new FocusabilityCondition(true), isFocused => { var attributes = new List <Tuple <string, string> > { Tuple.Create("type", "button") }; attributes.AddRange(behavior.GetAttributes()); if (isFocused) { attributes.Add(Tuple.Create("autofocus", "autofocus")); } return new DisplayableElementFocusDependentData( attributes: attributes, includeIdAttribute: behavior.IncludesIdAttribute(), jsInitStatements: behavior.GetJsInitStatements(context.Id) + style.GetJsInitStatements(context.Id)); }), classes: style.GetClasses().Add(classes ?? ElementClassSet.Empty), children: elementChildren, etherealChildren: elementEtherealChildren)); }).ToCollection(); }
/// <summary> /// Creates a submit button. /// </summary> /// <param name="style">The style.</param> /// <param name="displaySetup"></param> /// <param name="classes">The classes on the button.</param> /// <param name="postBack">Pass null to use the post-back corresponding to the first of the current data modifications.</param> public SubmitButton(ButtonStyle style, DisplaySetup displaySetup = null, ElementClassSet classes = null, PostBack postBack = null) { var elementChildren = style.GetChildren(); var postBackAction = new PostBackFormAction(postBack ?? FormState.Current.PostBack); children = new DisplayableElement( context => { FormAction action = postBackAction; action.AddToPageIfNecessary(); if (EwfPage.Instance.SubmitButtonPostBack != null) { throw new ApplicationException("A submit button already exists on the page."); } EwfPage.Instance.SubmitButtonPostBack = postBackAction.PostBack; return(new DisplayableElementData( displaySetup, () => new DisplayableElementLocalData( "button", attributes: new[] { Tuple.Create("name", EwfPage.ButtonElementName), Tuple.Create("value", "v") }, jsInitStatements: style.GetJsInitStatements(context.Id)), classes: style.GetClasses().Add(classes ?? ElementClassSet.Empty), children: elementChildren)); }).ToCollection(); }
/// <summary> /// Creates a button. /// </summary> /// <param name="style">The style.</param> /// <param name="displaySetup"></param> /// <param name="behavior">The behavior. Pass null to use the form default action.</param> /// <param name="classes">The classes on the button.</param> public EwfButton(ButtonStyle style, DisplaySetup displaySetup = null, ButtonBehavior behavior = null, ElementClassSet classes = null) { behavior = behavior ?? new FormActionBehavior(FormState.Current.DefaultAction); var elementChildren = style.GetChildren(); var elementEtherealChildren = behavior.GetEtherealChildren(); children = new DisplayableElement( context => { behavior.AddPostBack(); return(new DisplayableElementData( displaySetup, () => new DisplayableElementLocalData( "button", attributes: Tuple.Create("type", "button").ToCollection().Concat(behavior.GetAttributes()), includeIdAttribute: behavior.IncludesIdAttribute(), jsInitStatements: behavior.GetJsInitStatements(context.Id) + style.GetJsInitStatements(context.Id)), classes: style.GetClasses().Add(classes ?? ElementClassSet.Empty), children: elementChildren, etherealChildren: elementEtherealChildren)); }).ToCollection(); }
/// <summary> /// Creates a submit button. /// </summary> /// <param name="style">The style.</param> /// <param name="displaySetup"></param> /// <param name="classes">The classes on the button.</param> /// <param name="postBack">Pass null to use the post-back corresponding to the first of the current data modifications.</param> public SubmitButton(ButtonStyle style, DisplaySetup displaySetup = null, ElementClassSet classes = null, PostBack postBack = null) { var elementChildren = style.GetChildren(); var postBackAction = new PostBackFormAction(postBack ?? FormState.Current.PostBack); children = new DisplayableElement( context => { FormAction action = postBackAction; action.AddToPageIfNecessary(); if (PageBase.Current.SubmitButtonPostBack != null) { throw new ApplicationException("A submit button already exists on the page."); } PageBase.Current.SubmitButtonPostBack = postBackAction.PostBack; return(new DisplayableElementData( displaySetup, () => new DisplayableElementLocalData( "button", new FocusabilityCondition(true), isFocused => { var attributes = new List <ElementAttribute> { new ElementAttribute("name", PageBase.ButtonElementName), new ElementAttribute("value", "v") }; if (isFocused) { attributes.Add(new ElementAttribute("autofocus")); } return new DisplayableElementFocusDependentData(attributes: attributes, jsInitStatements: style.GetJsInitStatements(context.Id)); }), classes: style.GetClasses().Add(classes ?? ElementClassSet.Empty), children: elementChildren)); }).ToCollection(); }