public static void RegisterClientCheckEvents(Page pg, string formID) { if (pg == null) { throw new ArgumentNullException("pg"); } ClientScriptManager clientScript = pg.ClientScript; string checkHeadScript = GetCheckHeadScript(); string checkHeadReverseScript = GetCheckHeadReverseScript(); string clickCheckScript = GetClickCheckScript(); if (!clientScript.IsClientScriptBlockRegistered("clientScriptCheckAll")) { clientScript.RegisterClientScriptBlock(pg.GetType(), "clientScriptCheckAll", checkHeadScript.Replace("[frmID]", formID)); } if (!clientScript.IsClientScriptBlockRegistered("clientReverseScript")) { clientScript.RegisterClientScriptBlock(pg.GetType(), "clientScriptCheckReverse", checkHeadReverseScript.Replace("[frmID]", formID)); } if (!clientScript.IsClientScriptBlockRegistered("clientCheckClickScript")) { clientScript.RegisterClientScriptBlock(pg.GetType(), "clientCheckClickScript", clickCheckScript.Replace("[frmID]", formID)); } RegisterAttributes(pg); }
protected void lnkConfrePrint_onclick(Object sender, EventArgs e) { clearMessages(); LinkButton btn = (LinkButton)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; int _lgid = Convert.ToInt32(grdvConfPenReprint.DataKeys[row.RowIndex].Value); LetterGen gObj = new LetterGen("EBAnamespace"); Type cstype = this.GetType(); try { string[] _Letter = gObj.reprintLetters(_lgid); ClientScriptManager cs = Page.ClientScript; string _filepath = "C:\\EBATemp\\"; string _file = _filepath + "Print.xml"; int _seq = 0; foreach (string _lt in _Letter) { try { if (!cs.IsClientScriptBlockRegistered(_seq + "SaveExcel")) { cs.RegisterClientScriptBlock(typeof(Page), _seq + "SaveExcel", "SaveTextFile('" + _lt.Replace(Environment.NewLine, "") + "', '" + _file.Replace("\\", "\\\\") + "');", true); } if (!cs.IsClientScriptBlockRegistered(_seq + "PrintWord")) { cs.RegisterClientScriptBlock(typeof(Page), _seq + "PrintWord", "PrintWord('" + _file.Replace("\\", "\\\\") + "');", true); } } finally { EndProcess(); if (!cs.IsClientScriptBlockRegistered(_seq + "DeleteFile")) { cs.RegisterClientScriptBlock(typeof(Page), _seq + "DeleteFile", "DeleteFile('" + _file.Replace("\\", "\\\\") + "');", true); } } _seq++; } } catch (Exception ex) { errorDiv4.Visible = true; lbl_error4.Text = "Some error occured while printing letters - " + ex.Message; } finally { grdvConfPen.DataBind(); grdvConfPenReprint.DataBind(); } }
protected void lnkViewStg_onclick(Object sender, EventArgs e) { clearMessages(); LinkButton btn = (LinkButton)sender; GridViewRow row = (GridViewRow)btn.NamingContainer; string _schemaUri = "EBAnamespace"; string _schemaAlias = "EBAHRA"; try { int _lgid = Convert.ToInt32(grdvStageTemplates.DataKeys[row.RowIndex].Value); string _letterCode = LettersGenDAL.getLetterTypeCodeStage(_lgid); string _schemaPath = ""; if (_letterCode.Equals("HRB1") || _letterCode.Equals("HRB2")) { _schemaPath = FilePaths.getFilePath("SchemaValid"); } else { _schemaPath = FilePaths.getFilePath("Schema"); } string _template = LettersGenDAL.getStageTemplate(_lgid); string _filepath = "C:\\EBATemp\\"; string _file = _filepath + "Template.xml"; int _seq = 0; ClientScriptManager cs = Page.ClientScript; if (!cs.IsClientScriptBlockRegistered(_seq + "DeleteFile")) { cs.RegisterClientScriptBlock(typeof(Page), _seq + "DeleteFile", "DeleteFile('" + _file.Replace("\\", "\\\\") + "');", true); } if (!cs.IsClientScriptBlockRegistered(_seq + "SaveFile")) { cs.RegisterClientScriptBlock(typeof(Page), _seq + "SaveFile", "SaveFile('" + _template.Replace(Environment.NewLine, "") + "', '" + _file.Replace("\\", "\\\\") + "');", true); } if (!cs.IsClientScriptBlockRegistered(_seq + "DownloadWord")) { cs.RegisterClientScriptBlock(typeof(Page), _seq + "DownloadWord", "DownloadTemplate('" + _file.Replace("\\", "\\\\") + "', '" + _schemaPath + "','" + _schemaAlias + "','" + _schemaUri + "');", true); } } catch (Exception ex) { errorDiv3.Visible = true; lblErr3.Text = "Error downloading File - " + ex.Message; } }
protected override void CreateChildControls() { Controls.Clear(); if (Field == null) { return; } if (Field.ReadOnly || ControlMode == SPControlMode.Display) { ctrl_Label = new Label { ID = Field.InternalName }; Controls.Add(ctrl_Label); } else { ClientScriptManager cs = this.Page.ClientScript; Type csType = this.GetType(); //if (!cs.IsClientScriptBlockRegistered(csType, "clienttemplates.js")) { // cs.RegisterClientScriptBlock(csType, "clienttemplates.js", "<script type=\"text/javascript\" src=\"/_layouts/15/clienttemplates.js\"></script>", false); //} if (!cs.IsClientScriptBlockRegistered(csType, "clientforms.js")) { cs.RegisterClientScriptBlock(csType, "clientforms.js", "<script type=\"text/javascript\" src=\"/_layouts/15/clientforms.js\"></script>", false); } if (!cs.IsClientScriptBlockRegistered(csType, "clientpeoplepicker.js")) { cs.RegisterClientScriptBlock(csType, "clientpeoplepicker.js", "<script type=\"text/javascript\" src=\"/_layouts/15/clientpeoplepicker.js\"></script>", false); } if (!cs.IsClientScriptBlockRegistered(csType, "autofill.js")) { cs.RegisterClientScriptBlock(csType, "autofill.js", "<script type=\"text/javascript\" src=\"/_layouts/15/autofill.js\"></script>", false); } //if (!cs.IsClientScriptBlockRegistered(csType, "sp.js")) { // cs.RegisterClientScriptBlock(csType, "sp.js", "<script type=\"text/javascript\" src=\"/_layouts/15/sp.js\"></script>", false); //} //if (!cs.IsClientScriptBlockRegistered(csType, "sp.runtime.js")) { // cs.RegisterClientScriptBlock(csType, "sp.runtime.js", "<script type=\"text/javascript\" src=\"/_layouts/15/sp.runtime.js\"></script>", false); //} //if (!cs.IsClientScriptBlockRegistered(csType, "sp.core.js")) { // cs.RegisterClientScriptBlock(csType, "sp.core.js", "<script type=\"text/javascript\" src=\"/_layouts/15/sp.core.js\"></script>", false); //} div = new HtmlGenericControl("div"); div.ID = Field.InternalName + "_userField"; Controls.Add(div); } fld_Value = new HiddenField { ID = Field.InternalName + "_userFieldValue", ClientIDMode = ClientIDMode.Static }; Controls.Add(fld_Value); }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); //if (!this.DesignMode & !Page.IsPostBack) if (!this.DesignMode) { ClientScriptManager cm = this.Page.ClientScript; if (!cm.IsClientScriptBlockRegistered("CallServer")) { // String callbackReference = cm.GetCallbackEventReference(this, "arg", "ReceiveServerData", "", true); String callbackReference = cm.GetCallbackEventReference(this, "arg", "ReceiveServerData", "''", true); callbackReference = callbackReference.Replace("'" + ClientID + "'", "ID"); String callBackScript = "function CallServer(ID,arg) {" + callbackReference + "; }"; //String callBackScript = "function CallServer(arg, context) {alert(arg.toString()+' '+context.toString()); }"; cm.RegisterClientScriptBlock(this.GetType(), "CallServer", callBackScript, true); } if (!cm.IsClientScriptBlockRegistered("CallPostBack")) { String postBackReference = cm.GetPostBackEventReference(this, "arg"); postBackReference = postBackReference.Replace("'" + ClientID + "'", "ID"); postBackReference = postBackReference.Replace("'arg'", "arg"); string postBackScript = "function CallPostBack(ID,arg) {" + postBackReference + ";}"; cm.RegisterClientScriptBlock(this.GetType(), "CallPostBack", postBackScript, true); } //string StartUP = "window.onload = function() {Initialize(\"" + ClientID + "\")}"; string StartUP = "Initialize(\"" + ClientID + "\");"; cm.RegisterStartupScript(this.GetType(), "StartUp" + ClientID, StartUP, true); string resourceName = "DotSpatial.WebControls.Script.WebDsScript.js"; cm.RegisterClientScriptResource(GetType(), resourceName); resourceName = "DotSpatial.WebControls.Script.WebToolBar.js"; cm.RegisterClientScriptResource(GetType(), resourceName); resourceName = "DotSpatial.WebControls.Script.wz_jsgraphics.js"; cm.RegisterClientScriptResource(GetType(), resourceName); // These .js scripts no longer needed with HTML tooltips (title): // resourceName = "DotSpatial.WebControls.Script.wz_tooltip.js"; // cm.RegisterClientScriptResource(GetType(), resourceName); // resourceName = "DotSpatial.WebControls.Script.tip_balloon.js"; // cm.RegisterClientScriptResource(GetType(), resourceName); resourceName = "DotSpatial.WebControls.Script.CookieManager.js"; cm.RegisterClientScriptResource(GetType(), resourceName); } }
protected void Page_Load(object sender, EventArgs e) { Page.Header.Controls.Add(new LiteralControl("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResolveUrl("~/Styles/jquery-ui.css") + "\" />")); ClientScriptManager cs = Page.ClientScript; if (!cs.IsClientScriptIncludeRegistered("jquery")) { cs.RegisterClientScriptInclude("jquery", ResolveClientUrl("Scripts/jquery-1.11.2.min.js")); } if (!cs.IsClientScriptIncludeRegistered("jquery-ui")) { cs.RegisterClientScriptInclude("jquery-ui", ResolveClientUrl("Scripts/jquery-ui.min.js")); } if (!cs.IsClientScriptIncludeRegistered("jquery-ui-custom")) { cs.RegisterClientScriptInclude("jquery-ui-custom", ResolveClientUrl("Scripts/jquery-ui-1.10.2.custom.min.js")); } if (!cs.IsClientScriptIncludeRegistered("common")) { cs.RegisterClientScriptInclude("common", ResolveClientUrl("Scripts/common.js?=6")); } if (!cs.IsClientScriptIncludeRegistered("shell")) { cs.RegisterClientScriptInclude("shell", ResolveClientUrl("Scripts/shell.js")); } if (!cs.IsClientScriptIncludeRegistered("popupWindow")) { cs.RegisterClientScriptInclude("popupWindow", ResolveClientUrl("Scripts/popupWindow.js")); } if (!cs.IsClientScriptBlockRegistered("underscore")) { cs.RegisterClientScriptInclude("underscore", ResolveClientUrl("Scripts/underscore-min.js")); } if (!cs.IsClientScriptBlockRegistered("moment")) { cs.RegisterClientScriptInclude("moment", ResolveClientUrl("Scripts/moment.min.js")); } if (!cs.IsClientScriptBlockRegistered("reports")) { cs.RegisterClientScriptInclude("reports", ResolveClientUrl("Scripts/reports.js")); } if (!cs.IsClientScriptBlockRegistered("filter")) { cs.RegisterClientScriptInclude("filter", ResolveClientUrl("Scripts/filter.js")); } if (!cs.IsClientScriptBlockRegistered("iti_FilterContainer")) { cs.RegisterClientScriptInclude("iti_FilterContainer", ResolveClientUrl("Scripts/iti_FilterContainer.js")); } }
protected void Page_Load(object sender, EventArgs e) { Page.Header.Controls.Add(new LiteralControl("<link rel=\"stylesheet\" type=\"text/css\" href=\"" + ResolveUrl("~/Styles/jquery-ui.css") + "\" />")); ClientScriptManager cs = Page.ClientScript; if (!cs.IsClientScriptIncludeRegistered("jquery")) { cs.RegisterClientScriptInclude("jquery", ResolveClientUrl("Scripts/jquery-1.11.2.min.js")); } if (!cs.IsClientScriptIncludeRegistered("jquery-ui")) { cs.RegisterClientScriptInclude("jquery-ui", ResolveClientUrl("Scripts/jquery-ui.min.js")); } if (!cs.IsClientScriptIncludeRegistered("common")) { cs.RegisterClientScriptInclude("common", ResolveClientUrl("Scripts/common.js")); } if (!cs.IsClientScriptIncludeRegistered("shell")) { cs.RegisterClientScriptInclude("shell", ResolveClientUrl("Scripts/shell.js")); } if (!cs.IsClientScriptIncludeRegistered("popupWindow")) { cs.RegisterClientScriptInclude("popupWindow", ResolveClientUrl("Scripts/popupWindow.js")); } if (!cs.IsClientScriptBlockRegistered("underscore")) { cs.RegisterClientScriptInclude("underscore", ResolveClientUrl("Scripts/underscore-min.js")); } if (!cs.IsClientScriptBlockRegistered("underscorestring")) { cs.RegisterClientScriptInclude("underscorestring", ResolveClientUrl("Scripts/underscore.string.min.js")); } if (!cs.IsClientScriptBlockRegistered("moment")) { cs.RegisterClientScriptInclude("moment", ResolveClientUrl("Scripts/moment.min.js")); } if (Request.ServerVariables["NeedsPDFViewer"] != null && Request.ServerVariables["NeedsPDFViewer"].ToString().ToLower() == "true") { cs.RegisterClientScriptInclude("pdfviewer", ResolveClientUrl("Scripts/pdf.js")); cs.RegisterClientScriptInclude("pdfviewer", ResolveClientUrl("Scripts/pdf.worker.js")); } }
/// <summary> /// Add the client script source. /// </summary> /// <param name="type">The type of the client script to register.</param> /// <param name="page">The page to register the client script on.</param> /// <param name="key">The key of the client script to register.</param> /// <param name="source">The source relative url.</param> public static void AddClientScriptSource(Type type, Page page, string key, string source) { // Make sure the page reference exists. if (type == null) { throw new ArgumentNullException("type"); } if (page == null) { throw new ArgumentNullException("page"); } if (key == null) { throw new ArgumentNullException("key"); } if (source == null) { throw new ArgumentNullException("source"); } // Get the client script collection on the current page. ClientScriptManager clientScript = page.ClientScript; // Check to see if the client script is already registered. if (!clientScript.IsClientScriptBlockRegistered(type, key)) { // Register the client script. clientScript.RegisterClientScriptBlock(type, key, "<script type=\"text/javascript\" src=\"" + source + "\"></script>", false); } }
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); if (ctrl_CheckList != null) { // CUSTOM VALIDATOR for CheckBoxList Type cstype = this.GetType(); ClientScriptManager csm = Page.ClientScript; string csname = "CheckBoxListValidatorFor" + Field.InternalName; if (!csm.IsClientScriptBlockRegistered(csname)) { //StringBuilder cstext = new StringBuilder(); //cstext.AppendFormat("<script type=\"text/javascript\"> function DoValidationFor_{0}(sender, args) {{", Field.InternalName); //cstext.AppendFormat("var checkBoxList = document.getElementById('{0}');", ctrl_CheckList.ClientID.Substring(0, ctrl_CheckList.ClientID.LastIndexOf("_" + Field.InternalName))); //cstext.Append("var checkboxes = checkBoxList.getElementsByTagName('input');"); //cstext.Append("var isValid = false;"); //cstext.Append("for (var i = 0; i < checkboxes.length; i++) {"); //cstext.Append(" if (checkboxes[i].checked) {"); //cstext.Append(" isValid = true;"); //cstext.Append(" break;"); //cstext.Append(" }"); //cstext.Append("}"); //cstext.Append("args.IsValid = isValid;} </"); //cstext.Append("script>"); //csm.RegisterClientScriptBlock(cstype, csname, cstext.ToString(), false); } } }
public void mensajeAlerta() { String csname1 = "PopupScript"; String csname2 = "ButtonClickScript"; Type cstype = this.GetType(); // Get a ClientScriptManager reference from the Page class. ClientScriptManager cs = Page.ClientScript; // Check to see if the startup script is already registered. if (!cs.IsStartupScriptRegistered(cstype, csname1)) { String cstext1 = "alert('Hello World');"; cs.RegisterStartupScript(cstype, csname1, cstext1, true); } // Check to see if the client script is already registered. if (!cs.IsClientScriptBlockRegistered(cstype, csname2)) { StringBuilder cstext2 = new StringBuilder(); cstext2.Append("<script type=\"text/javascript\"> function DoClick() {"); cstext2.Append("Form1.Message.value='Text from client script.'} </"); cstext2.Append("script>"); cs.RegisterClientScriptBlock(cstype, csname2, cstext2.ToString(), false); } }
private void AddJavaScriptToPage(Page page) { if (page != null) { string innerFadeScript = "InnerFadeScript"; ClientScriptManager clientScriptManager = Page.ClientScript; Type csType = page.GetType(); StringBuilder scripts = new StringBuilder(); // register innerfade script plugin if (!clientScriptManager.IsClientScriptBlockRegistered(csType, innerFadeScript)) { if (bool.Parse(_rotatorSettings.GetSingleValue("UseExtensionJQuery"))) { scripts.AppendLine("<script type=\"text/javascript\" src=\"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js\"></script>"); } scripts.AppendFormat("<script type=\"text/javascript\" src=\"{0}Custom/Controls/FeaturedPostsRotator/js/jquery.innerfade.js\"></script>", Utils.AbsoluteWebRoot); scripts.AppendLine("<script type=\"text/javascript\">"); scripts.AppendLine("$(document).ready(function () {"); scripts.AppendLine("$('#show').innerFade({ indexContainer: '#index', currentItemContainer: '.current', totalItemsContainer: '.total', animationtype: 'fade', speed: 3000, timeout: 5000, type: 'sequence', prevLink: '.prev', nextLink: '.next', containerheight: 260 });"); scripts.AppendLine("});"); scripts.AppendLine("</script>"); page.ClientScript.RegisterStartupScript(csType, innerFadeScript, scripts.ToString()); } } }
/// <summary> /// Loads the Javascript file contents onto the page /// using the given url which must refer to this site. /// /// If the url starts with "http://" or "https://" /// then this method calls LoadFileReference instead. /// </summary> /// <param name="page">The page on which to load</param> /// <param name="url">The url of the file</param> /// <param name="addScriptTag">If true then add script tags</param> public static void LoadFileContents (Page page, string url, bool addScriptTag) { if (url.StartsWith(FileTools.httpStart)) { LoadFileReference(page, url); return; } if (url.StartsWith(FileTools.httpsStart)) { LoadFileReference(page, url); return; } ClientScriptManager clientscriptmanager = page.ClientScript; Type type = page.GetType(); if (!clientscriptmanager.IsClientScriptBlockRegistered(type, url)) { string filepath = page.MapPath(url); string contents = FileTools.GetFileAsText(filepath); LoadScriptString(page, url, contents, addScriptTag); } }
/// <summary> /// Loads the given script onto this page with the given key /// to prevent multiple loads by different method calls. /// </summary> /// <param name="page">The page on which to load</param> /// <param name="key">The key to prevent multiple loads</param> /// <param name="script">The script to load</param> /// <param name="addScriptTag">If true then add script tags</param> public static void LoadScriptString (Page page, string key, string script, bool addScriptTag) { ClientScriptManager clientscriptmanager = page.ClientScript; Type type = page.GetType(); if (!clientscriptmanager.IsClientScriptBlockRegistered(type, key)) { string contents = ""; if (addScriptTag) { StringBuilder builder = new StringBuilder(); builder.Append(script_inline_1); builder.Append(script); builder.Append("\n"); builder.Append(script_inline_2); contents = builder.ToString(); } else { contents = script; } clientscriptmanager.RegisterClientScriptBlock (type, key, contents, false); } }
protected override void OnInit(EventArgs e) { base.OnInit(e); ClientScriptManager csm = Page.ClientScript; Type csType = this.Page.GetType(); String csKey = "BIResources"; if (!csm.IsClientScriptBlockRegistered(csType, csKey)) { System.Text.StringBuilder sb = new System.Text.StringBuilder(); sb.Append("<script type=\"text/javascript\">"); sb.AppendFormat("var Milion_CurrencySymbol = '{0}';", Resources.BI.Milion_CurrencySymbol); sb.Append("</script>"); csm.RegisterClientScriptBlock(csType, csKey, sb.ToString()); } Control wc; switch (Get_Param_SubMenuCode()) { case "asis_AC": wc = LoadControl("wcACCube.ascx"); break; case "asis_IC": wc = LoadControl("wcICCube.ascx"); break; default: wc = LoadControl("wcSaleCube.ascx"); break; } AnalysisPlaceHolder.Controls.Add(wc); }
/// <summary>返回默认的reloadForm实现,配合Box.js中的Dialog.CloseAndRefresh</summary> /// <returns></returns> public static bool RegisterReloadFormJs(ClientScriptManager script, bool isPostback) { if (!script.IsClientScriptBlockRegistered(typeof(LinkBox), "ReloadFormJs")) { script.RegisterClientScriptBlock(typeof(LinkBox), "ReloadFormJs", Helper.JsMinSimple(!XControlConfig.Debug, @" function reloadForm(){ if(!" + ("" + isPostback).ToLower() + @"){ location.reload(); return true; } var buttons = document.getElementsByTagName('input'); for(var i=0;i<buttons.length;i++){ var ele = buttons[i]; if((ele.type === 'submit' || ele.type === 'button') && ele.value === '查询'){ if(ele.click){ ele.click(); }else if(document.createEvent && ele.dispatchEvent){ var event = document.createEvent('MouseEvent'); event.initMouseEvent('click', true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null); ele.dispatchEvent(event); }else{ break; } return true; } } return false; }"), true); return(true); } return(false); }
/// <summary> /// Add the client style block. /// </summary> /// <param name="type">The type of the client style to register.</param> /// <param name="page">The page to register the client style on.</param> /// <param name="key">The key of the client style to register.</param> /// <param name="style">The client style literal to register.</param> public static void AddStylesheetBlock(Type type, Page page, string key, StringBuilder style) { // Make sure the page reference exists. if (type == null) { throw new ArgumentNullException("type"); } if (page == null) { throw new ArgumentNullException("page"); } if (key == null) { throw new ArgumentNullException("key"); } if (style == null) { throw new ArgumentNullException("style"); } // Get the client script collection on the current page. ClientScriptManager clientScript = page.ClientScript; // Check to see if the client script is already registered. if (!clientScript.IsClientScriptBlockRegistered(type, key)) { // Register the client script. clientScript.RegisterClientScriptBlock(type, key, "<style type=\"text/css\">" + "\r\n" + style.ToString() + "\r\n" + "</style>", false); } }
private void RegisterJavaScript(Store currentStore) { ContactMapDiv.Attributes.Add("Onload", "initialize()"); ContactMapDiv.Attributes.Add("OnResize", "initialize()"); String csname = "ContactMap"; ClientScriptManager cs = Page.ClientScript; String latitude = DataAccessContext.Configurations.GetValue("Latitude", currentStore); String longitude = DataAccessContext.Configurations.GetValue("Longitude", currentStore); String companyName = DataAccessContext.Configurations.GetValue(CultureUtilities.StoreCultureID, "CompanyName"); StringBuilder sb = new StringBuilder(); sb.AppendLine("function initialize() {"); sb.AppendLine(" var map_canvas = document.getElementById('" + ContactMapDiv.ClientID + "');"); sb.AppendLine(" var map_options = {"); sb.AppendLine(" center: new google.maps.LatLng(" + latitude + ", " + longitude + "),"); sb.AppendLine(" zoom: 15,"); sb.AppendLine(" mapTypeId: google.maps.MapTypeId.ROADMAP"); sb.AppendLine(" }"); sb.AppendLine(" var map = new google.maps.Map(map_canvas, map_options)"); sb.AppendLine(" var marker = new google.maps.Marker({"); sb.AppendLine(" position: new google.maps.LatLng(" + latitude + ", " + longitude + "),"); sb.AppendLine(" map: map,"); sb.AppendLine(" title: '" + companyName + "'"); sb.AppendLine(" });"); sb.AppendLine("}"); sb.AppendLine("google.maps.event.addDomListener(window, 'load', initialize);"); if (!cs.IsClientScriptBlockRegistered(this.GetType(), csname)) { cs.RegisterClientScriptBlock(this.GetType(), csname, sb.ToString(), true); } }
/// <summary> /// Checks to see if data is required /// </summary> /// <param name="e"></param> protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); //Setting Pager template //ControlBase.SetGridPaging(this); // only load data if either: // a) view state is disabled, so we need to fetch the data every time, or // b) view state is enabled, but either the data hasn't been loaded yet or a // paging/sorting event has occurred if (!DataGridLoaded) { InternalBinding(); } // Page can become null when we are connecting webparts if (Page != null) { ClientScriptManager clientScript = Page.ClientScript; string scriptName = "SPSGridView_Script"; if (!clientScript.IsClientScriptBlockRegistered(scriptName)) { clientScript.RegisterClientScriptBlock(GetType(), scriptName, GetScript(), true); } } }
/// <summary> /// Render js variable for Colour-coding /// </summary> private void RegisterFieldInfoAsJSVariable() { List <DbField> fields = this.ListFields.Select(x => x.GetDbField()).ToList(); var availableFields = fields.Where(x => x.InternalName == FieldNames.CONTENT_TYPE_ID || (!x.Hidden && (x.Type == SPFieldType.Choice || x.Type == SPFieldType.MultiChoice || x.Type == SPFieldType.Lookup || x.Type == SPFieldType.Boolean))) .Select(x => new { fieldTitle = x.DisplayName, fieldName = x.InternalName }); var availableFields_DynColoring = this.ListFields.Select(x => new { fieldTitle = x.FieldName, fieldName = x.InternalName }); // register global js variables JavaScriptSerializer jsSer = new JavaScriptSerializer(); Type csType = this.GetType(); string globalVarKey = "globalVariables"; string customScript = string.Format("var global_availableFields = {0};var global_availableFields_dynCol = {1};", jsSer.Serialize(availableFields), jsSer.Serialize(availableFields_DynColoring)); ClientScriptManager csm = Page.ClientScript; if (!csm.IsClientScriptBlockRegistered(csType, globalVarKey)) { csm.RegisterClientScriptBlock(csType, globalVarKey, customScript, true); } }
/// <summary> /// Loads a Javascript file reference onto the page /// to the file at the given url. /// /// The url may be: /// /// 1. An absolute url "http://" or "https://" /// 2. A tilde url "~/" /// 3. A url relative to the given page /// /// </summary> /// <param name="page">The page on which to load</param> /// <param name="url">The url of the file</param> public static void LoadFileReference(Page page, string url) { ClientScriptManager clientscriptmanager = page.ClientScript; Type type = page.GetType(); if (!clientscriptmanager.IsClientScriptBlockRegistered(type, url)) { string pageTildePath = FileTools.GetTildePath(page); string resolvedUrl = FileTools.GetResolvedUrl(pageTildePath, url); StringBuilder builder = new StringBuilder(); builder.Append(script_file_1); builder.Append(resolvedUrl); builder.Append(script_file_2); string contents = builder.ToString(); clientscriptmanager.RegisterClientScriptBlock (type, url, contents, false); } }
public static void StyleSheet([NotNull] this Control thisValue, [NotNull] IEnumerable <Uri> urls) { Page page = AsPage(thisValue); if (page?.Header == null) { return; } ClientScriptManager csm = page.ClientScript; Type type = thisValue.GetType(); foreach (Uri url in urls) { string key = UriHelper.GetFileName(url); if (string.IsNullOrEmpty(key) || csm.IsClientScriptBlockRegistered(type, key)) { continue; } HtmlLink link = new HtmlLink { Href = $"{url}?t={DateTime.Now.Ticks}" }; link.Attributes.Add("rel", "stylesheet"); link.Attributes.Add("type", "text/css"); page.Header.Controls.Add(link); csm.RegisterClientScriptBlock(type, key, string.Empty); } }
public static void RegisterZipScriptBlock(ClientScriptManager csManager, Type type, string countryID) { string newLine = Environment.NewLine; if (!csManager.IsClientScriptBlockRegistered(type, "MCU_ValidateZip")) { StringBuilder csText = new StringBuilder(); csText.Append("<script language=\"javascript\">" + newLine); csText.Append("<!--" + newLine); csText.Append("function MCU_ValidateZip(source, arguments) {" + newLine); csText.Append("var oCountry = document.getElementById(\"" + countryID + "\");" + newLine); csText.Append("var vCountry = oCountry.options[oCountry.selectedIndex].value;" + newLine); csText.Append("var re;" + newLine); csText.Append("if (vCountry == 1)" + newLine); csText.Append("re = new RegExp(/(^\\d{5}$)|(^\\d{5}-\\d{4}$)/); // United States." + newLine); csText.Append("else" + newLine); csText.Append("re = new RegExp(/^[A-Z]{1}\\d{1}[A-Z]{1} \\d{1}[A-Z]{1}\\d{1}$/); // Canada." + newLine); csText.Append("if (arguments.Value.match(re)) arguments.IsValid = true; else arguments.IsValid = false;" + newLine); csText.Append("}" + newLine); csText.Append("// -->" + newLine); csText.Append("</script>" + newLine); csManager.RegisterClientScriptBlock(type, "MCU_ValidateZip", csText.ToString(), false); } }
protected System.Web.UI.WebControls.Literal litSourceOrder;//关联的订单号 protected void Page_Load(object sender, System.EventArgs e) { if (string.IsNullOrEmpty(this.Page.Request.QueryString["ReplaceId"])) { base.GotoResourceNotFound(); return; } string key = "orderdetails-frame"; string script = string.Format("<script>if(window.parent.frames.length == 0) window.location.href=\"{0}\";</script>", Globals.ApplicationPath + "/admin/default.html"); ClientScriptManager clientScript = this.Page.ClientScript; if (!clientScript.IsClientScriptBlockRegistered(key)) { clientScript.RegisterClientScriptBlock(base.GetType(), key, script); } int.TryParse(this.Page.Request.QueryString["ReplaceId"], out returnsId); this.replaceInfo = OrderHelper.GetReplaceInfo(this.returnsId); this.orderId = replaceInfo.OrderId; if (this.replaceInfo == null) { base.Response.Write("<h3 style=\"color:red;\">退货单不存在,或者已被删除。</h3>"); base.Response.End(); } else { } if (!this.Page.IsPostBack) { BindReturnsData(); } }
public static void ClientScriptHeaderInclude([NotNull] this Control thisValue, [NotNull] IEnumerable <Uri> urls) { Page page = AsPage(thisValue); if (page?.Header == null) { return; } ClientScriptManager csm = page.ClientScript; Type type = thisValue.GetType(); foreach (Uri url in urls) { string key = UriHelper.GetFileName(url); if (string.IsNullOrEmpty(key) || csm.IsClientScriptBlockRegistered(type, key)) { continue; } Literal js = new Literal { ID = key, Text = $"{Environment.NewLine}<{HtmlTextWriterTag.Script} {HtmlTextWriterAttribute.Type}=\"text/javascript\" {HtmlTextWriterAttribute.Src}=\"{url}?t={DateTime.Now.Ticks}\"></{HtmlTextWriterTag.Script}>" }; page.Header.Controls.Add(js); } }
private void RegisterFacebookCommentScript() { if (DataAccessContext.Configurations.GetBoolValue("FacebookCommentEnabled")) { string appId = DataAccessContext.Configurations.GetValue("FacebookCommentAPIKey"); StringBuilder sb = new StringBuilder(); sb.Append("(function(d, s, id) {"); sb.Append(" var js,fjs = d.getElementsByTagName(s)[0];"); sb.Append(" if (d.getElementById(id)) return;"); sb.Append(" js = d.createElement(s); js.id = id;"); sb.Append(" js.src = \"//connect.facebook.net/en_US/all.js#xfbml=1&appId=" + appId + "\";"); sb.Append(" fjs.parentNode.insertBefore(js, fjs);"); sb.Append(" } (document, 'script', 'facebook-jssdk')"); sb.Append(" );"); sb.AppendLine(); String csname = "FacebookCommentBoxScript"; ClientScriptManager cs = Page.ClientScript; if (!cs.IsClientScriptBlockRegistered(this.GetType(), csname)) { cs.RegisterClientScriptBlock(this.GetType(), csname, sb.ToString(), true); } } }
/// <summary> /// 注册一个客户端脚本块 /// </summary> /// <param name="key">要注册脚本的键名</param> /// <param name="scriptText">要注册的脚本块</param> /// <param name="isScriptTag">脚本标记添加标识,指示是否对脚本块自动添加script标记对, /// 如果设置为true,则在脚本块中不用包含script标记对</param> public static void RegisterClientScriptBlock(string key, string scriptText, bool isScriptTag) { try { //获取Page对象 Page page = HttpContext.Current.Handler as Page; if (!ValidationHelper.IsNullOrEmpty(page)) { //获取ClientScriptManager对象 ClientScriptManager csm = page.ClientScript; //获取要注册脚本块的类型 Type type = page.GetType(); //判断客户端脚本块是否注册 if (!csm.IsClientScriptBlockRegistered(type, key)) { //如果未注册,则进行注册 csm.RegisterClientScriptBlock(type, key, scriptText, isScriptTag); } } } catch (Exception ex) { throw ex; } }
/// <summary> /// Creates Templates for new Letter Types (Default Schema Employee.xml) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void lnkCreate_onclick(Object sender, EventArgs e) { clearMessages(); string _fpath = ""; _fpath = FilePaths.getFilePath("Schema"); _fpath = _fpath.Replace("%20", " "); lnkInstall.Attributes.Add("onclick", "InstallDocSchema('" + _fpath + "','" + "EBAnamespace" + "')"); int _seq = 0; ClientScriptManager cs = Page.ClientScript; try { if (!cs.IsClientScriptBlockRegistered(_seq + "CreateFile")) { cs.RegisterClientScriptBlock(typeof(Page), _seq + "CreateFile", "InstallDocSchema('" + _fpath + "','" + "EBAnamespace" + "')", true); } } catch (Exception ex) { errorDiv1.Visible = true; lblErrorTemplates.Text = "Error Creating File - " + ex.Message; } }
private void IncludeTheCssAndJavaScript() { ClientScriptManager cs = Page.ClientScript; // Include the jQuery library (if not already included) string jqueryURL = this.TemplateSourceDirectory + "/Scripts/jquery-1.3.2.js"; if (!cs.IsStartupScriptRegistered(jqueryURL)) { cs.RegisterClientScriptInclude(jqueryURL, jqueryURL); } // Include the ErrorSuccessNotifier.js library (if not already included) string notifierScriptURL = this.TemplateSourceDirectory + "/Scripts/ErrorSuccessNotifier.js"; if (!cs.IsStartupScriptRegistered(notifierScriptURL)) { cs.RegisterClientScriptInclude(notifierScriptURL, notifierScriptURL); } // Include the ErrorSuccessNotifier.css stylesheet (if not already included) string cssRelativeURL = this.TemplateSourceDirectory + "/Styles/ErrorSuccessNotifier.css"; if (!cs.IsClientScriptBlockRegistered(cssRelativeURL)) { string cssLinkCode = string.Format( @"<link href='{0}' rel='stylesheet' type='text/css' />", cssRelativeURL); cs.RegisterClientScriptBlock(this.GetType(), cssRelativeURL, cssLinkCode); } }
/// <summary> /// Loads a CSS file reference onto the page /// to the file at the given url /// with the given CSS media attribute. /// /// The url may be: /// /// 1. An absolute url "http://" or "https://" /// 2. A tilde url "~/" /// 3. A url relative to the given page /// /// The media parameter may be used to give /// the CCS media attribute. The parameter /// is ignored if it is null or empty. /// </summary> /// <param name="page">The page on which to load</param> /// <param name="url">The url of the file</param> /// <param name="media">The CSS media attribute if any</param> public static void LoadFileReference(Page page, string url, string media) { ClientScriptManager clientscriptmanager = page.ClientScript; Type type = page.GetType(); if (!clientscriptmanager.IsClientScriptBlockRegistered(type, url)) { string pageTildePath = FileTools.GetTildePath(page); string resolvedUrl = FileTools.GetResolvedUrl(pageTildePath, url); StringBuilder builder = new StringBuilder(); builder.Append(open_css_link); builder.Append(resolvedUrl); if ((media != null) && (media.Length > 0)) { builder.Append(media_css); builder.Append(media); } builder.Append(shut_css_link); string contents = builder.ToString(); clientscriptmanager.RegisterClientScriptBlock (type, url, contents, false); } }