Monday, March 12, 2012

TaxonomyWebTaggingControl in UpdatePanel with AJAX

When asyncronuous postback will happen it will not load the TaxonomyWebTaggingControl because DOM gets null.
Use below methode to load TaxonomyWebTaggingControl  after asyn postback.

private string GetReloadJavaScript(TaxonomyWebTaggingControl taxonomyControl)
            String script = String.Empty;
            String containerId = SPEncode.ScriptEncode(taxonomyControl.Controls[1].ClientID);
            Type type_TaxonomyWebTaggingControl = typeof(TaxonomyWebTaggingControl);
            MethodInfo mi_getOnloadJavascript = type_TaxonomyWebTaggingControl.GetMethod("getOnloadJavascript", BindingFlags.NonPublic | BindingFlags.Instance);
            String fullScript = (String)mi_getOnloadJavascript.Invoke(taxonomyControl, null);
            int pos = fullScript.IndexOf(String.Format("function {0}_load()", containerId));
            if (pos > -1)
                StringBuilder builder = new StringBuilder();
                builder.Append("var myPrm_" + taxonomyControl.ID + " = Sys.WebForms.PageRequestManager.getInstance();");
                builder.Append("myPrm_" + taxonomyControl.ID + ".add_endRequest(EndRequest_" + taxonomyControl.ID + ");");
                builder.Append("function EndRequest_" + taxonomyControl.ID + "(sender, args)");
                // we get te first part of the script needed to initialization
                // we start from pos 1, because we don't need the leading '{'
                builder.Append(fullScript.Substring(1, pos - 1));
                script = builder.ToString();
            return script;

How to call above methode

String key1 = "TaxonomyWebTaggingAjaxIncludeOnce1";
                if (!this.Page.ClientScript.IsClientScriptBlockRegistered(base.GetType(), key1))
                    this.Page.ClientScript.RegisterClientScriptBlock(base.GetType(), key1, GetReloadJavaScript(taxanomyProjectCategory_taxonomyControl), true);


give multiple call to methode for all taxonomy controls on page.

No comments:

Post a Comment

Seven steps to build and deploy SPFX web part to SharePoint

Install Node.JS Use this link to install Node.JS 2.        Install yeomen and gulp CMD>npm install –g y...