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)");
builder.Append("{");
// 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));
builder.Append("Microsoft.SharePoint.Taxonomy.ScriptForWebTaggingUI.onLoad('");
builder.Append(containerId);
builder.Append("');");
builder.Append("}}");
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.
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)");
builder.Append("{");
// 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));
builder.Append("Microsoft.SharePoint.Taxonomy.ScriptForWebTaggingUI.onLoad('");
builder.Append(containerId);
builder.Append("');");
builder.Append("}}");
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