protected string RenderPageButton(string textOrUrl, string disabledTexOrUrl, int index, PageButtonStyle pageButtonStyle, PageButtonType?pageButtonType, IDictionary <string, object> htmlAttributes = null, bool encoded = true) { if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } string buttonType = getPageButtonClass(pageButtonType); string buttonId = fieldId + "_" + buttonType; if (!pageButtonType.HasValue) { if (index < 0) { buttonId = buttonId + "_" + (-index).ToString(CultureInfo.InvariantCulture); } else { buttonId = buttonId + index.ToString(CultureInfo.InvariantCulture); } htmlAttributes["data-pager-index"] = index.ToString(CultureInfo.InvariantCulture); } htmlAttributes["id"] = buttonId; htmlAttributes["data-pager-button"] = buttonType; BasicHtmlHelper.AddClass(htmlAttributes, fieldId + "_class"); BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "cursor", "pointer"); switch (pageButtonStyle) { case PageButtonStyle.Button: htmlAttributes["type"] = "button"; htmlAttributes["value"] = htmlHelper.Encode(textOrUrl); return(string.Format(buttonSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes))); case PageButtonStyle.Image: htmlAttributes["src"] = textOrUrl; if (disabledTexOrUrl != null) { htmlAttributes["data-disabled-src"] = disabledTexOrUrl; htmlAttributes["data-enabled-src"] = textOrUrl; } return(string.Format(imgSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes))); default: htmlAttributes["href"] = "javascript:void(0);"; return(string.Format(linkSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes), encoded ? htmlHelper.Encode(textOrUrl): textOrUrl)); } }
public MvcHtmlString PageButton(string textOrUrl, PageButtonType pageButtonType, PageButtonStyle pageButtonStyle = PageButtonStyle.Link, IDictionary <string, object> htmlAttributes = null, string disabledUrl = null) { if (string.IsNullOrWhiteSpace(textOrUrl)) { throw (new ArgumentNullException("textOrUrl")); } if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } return (MvcHtmlString.Create( RenderPageField() + RenderPageButton( textOrUrl, disabledUrl, 0, pageButtonStyle, pageButtonType, htmlAttributes))); }
public MvcHtmlString PageButton(string textOrUrl, PageButtonType pageButtonType, PageButtonStyle pageButtonStyle = PageButtonStyle.Link, IDictionary <string, object> htmlAttributes = null, string disabledTextOrUrl = null) { if (string.IsNullOrWhiteSpace(textOrUrl)) { throw (new ArgumentNullException("textOrUrl")); } if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } int page = -1; switch (pageButtonType) { case PageButtonType.First: page = 1; if (currPage <= 1) { htmlAttributes["disabled"] = "disabled"; if (disabledTextOrUrl != null) { textOrUrl = disabledTextOrUrl; } } break; case PageButtonType.Last: if (totPages != null && totPages.HasValue && totPages.Value > currPage) { page = totPages.Value; } else { htmlAttributes["disabled"] = "disabled"; if (disabledTextOrUrl != null) { textOrUrl = disabledTextOrUrl; } page = currPage; } break; case PageButtonType.Next: if (totPages != null && totPages.HasValue) { if (totPages > currPage) { page = currPage + 1; } else { page = currPage; htmlAttributes["disabled"] = "disabled"; if (disabledTextOrUrl != null) { textOrUrl = disabledTextOrUrl; } } } else { page = currPage + 1; } break; case PageButtonType.Previous: page = 1; if (currPage <= 1) { htmlAttributes["disabled"] = "disabled"; if (disabledTextOrUrl != null) { textOrUrl = disabledTextOrUrl; } } else { page = currPage - 1; } break; case PageButtonType.GoTo: page = -1; if (totPages.HasValue && totPages <= 1) { htmlAttributes["disabled"] = "disabled"; if (disabledTextOrUrl != null) { textOrUrl = disabledTextOrUrl; } } break; default: break; } return (MvcHtmlString.Create( RenderPageField() + RenderPageButton( getPageButtonClass(pageButtonType), textOrUrl, page, pageButtonStyle, htmlAttributes))); }
protected string RenderPageButton(string name, string textOrUrl, int page, PageButtonStyle pageButtonStyle, IDictionary <string, object> htmlAttributes = null, bool encoded = true) { if (htmlAttributes == null) { htmlAttributes = new Dictionary <string, object>(); } string buttonId = null; if (!string.IsNullOrEmpty(fieldName)) { buttonId = BasicHtmlHelper.IdFromName( BasicHtmlHelper.AddField(fieldName, name)); } else { if (string.IsNullOrWhiteSpace(controllerName)) { buttonId = BasicHtmlHelper.IdFromName( BasicHtmlHelper.AddField("CurrentController_" + actionName + "_" + parameterName, name)); } else { buttonId = BasicHtmlHelper.IdFromName( BasicHtmlHelper.AddField(controllerName + "_" + actionName + "_" + parameterName, name)); } } string pageUrl = string.Empty; if (parameterName != null) { System.Web.Routing.RouteValueDictionary routeDictionary = null; if (otherParameters != null) { routeDictionary = otherParameters as System.Web.Routing.RouteValueDictionary; if (routeDictionary == null) { routeDictionary = new System.Web.Routing.RouteValueDictionary(otherParameters); } } else { routeDictionary = new System.Web.Routing.RouteValueDictionary(); } if (page < 0) { routeDictionary.Add(parameterName, templateSymbol); } else { routeDictionary.Add(parameterName, page); } pageUrl = UrlHelper.GenerateUrl( routeName, actionName, controllerName, protocol, hostname, fragment, routeDictionary, htmlHelper.RouteCollection, htmlHelper.ViewContext.RequestContext, true); } htmlAttributes["id"] = buttonId; string res; BasicHtmlHelper.SetDefaultStyle(htmlAttributes, "cursor", "pointer"); switch (pageButtonStyle) { case PageButtonStyle.Button: htmlAttributes["type"] = "button"; htmlAttributes["value"] = htmlHelper.Encode(textOrUrl); return (string.Format(buttonSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes), fieldName, pageString(page), buttonId, clientUrl(page, pageUrl), targetIdName, validationType)); case PageButtonStyle.Link: htmlAttributes["href"] = "javascript:void(0);"; if (htmlAttributes.ContainsKey("disabled") && htmlAttributes["disabled"].ToString() == "disabled" || htmlAttributes.ContainsKey("data-selected-page") && htmlAttributes["data-selected-page"].ToString() == "selected") { string prevstyle = BasicHtmlHelper.SetStyle(htmlAttributes, "color", "gray"); res = string.Format(linkSchemaDisabled, BasicHtmlHelper.GetAttributesString(htmlAttributes), fieldName, page, buttonId, encoded ? htmlHelper.Encode(textOrUrl) : textOrUrl, pageUrl, targetIdName, validationType); BasicHtmlHelper.SetAttribute(htmlAttributes, "style", prevstyle); } else { if (pageUrl.Length != 0 && targetIdName.Length == 0 && page >= 0) { htmlAttributes["href"] = pageUrl; res = string.Format(linkSchemaGet, BasicHtmlHelper.GetAttributesString(htmlAttributes), encoded ? htmlHelper.Encode(textOrUrl) : textOrUrl); } else { res = string.Format(linkSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes), fieldName, pageString(page), buttonId, encoded ? htmlHelper.Encode(textOrUrl) : textOrUrl, clientUrl(page, pageUrl), targetIdName, validationType); } } return(res); default: htmlAttributes["src"] = textOrUrl; if (htmlAttributes.ContainsKey("disabled") && htmlAttributes["disabled"].ToString() == "disabled") { string prevstyle = BasicHtmlHelper.SetStyle(htmlAttributes, "color", "gray"); res = string.Format(imgSchemaDisabled, BasicHtmlHelper.GetAttributesString(htmlAttributes), fieldName, page, buttonId, pageUrl, targetIdName, validationType); BasicHtmlHelper.SetAttribute(htmlAttributes, "style", prevstyle); } else { res = string.Format(imgSchema, BasicHtmlHelper.GetAttributesString(htmlAttributes), fieldName, pageString(page), buttonId, clientUrl(page, pageUrl), targetIdName, validationType); } return(res); } }