Pages

Search This Blog

Monday, April 25, 2011

Problem with sharepoint inputformtextbox control with updatepanel

When using SharePoint:InputFormTextBox control in UpdatePanel I faced one issue. On my webpart part page I had one SharePoint:InputFormTextBox control with one asp:DropDown control with autopostback property true. On SelectedIndexChanged event of that dropdown, InputformTextBox control appears without toolbar. This behaviour was coming because the InputformTextBox is a TextArea control. It needs script to achieve the rich text box feature when loading the page and in update panel due to partial postback the script was not loading. To fix this issue we are required to load that script. I am giving you the steps to fix this issue:
Step 1: Put this script function in design code.
<script language="javascript" type="text/javascript">
function CreateRichEdit(elementid)
{
if (browseris.ie5up && browseris.win32 && !IsAccessibilityFeatureEnabled()){
g_aToolBarButtons = null;
g_fRTEFirstTimeGenerateCalled=true;
RTE_ConvertTextAreaToRichEdit(elementid, true, true, "", "1033", null, null, null, null, null,"FullHtml", "\u002f",null,null,null,null);
RTE_TextAreaWindow_OnLoad(elementid);
RTE_DocEditor_AdjustHeight(elementid);
RTE_DocEditor_AdjustWidth(elementid);
}
else{
document.write("&nbsp;<br><SPAN class=ms-formdescription><a href='javascript:HelpWindowKey(\"nsrichtext\")'>Click for help about adding basic HTML formatting.</a></SPAN>&nbsp;<br>");
};
}
</script>


Step 2: Put this code in code behind file

protected void Page_PreRender(object sender, EventArgs e)
{
ScriptManager.RegisterStartupScript(this.Page, this.Page.GetType(), "@@CreateRichEdit", "<script>CreateRichEdit('" + InputformTextbox.ClientID + "');</script>", false);
}

Thanks
Prabhat

2 comments:

  1. Please add following line
    RTE_GiveEditorFirstFocus(elementid);
    below
    RTE_TextAreaWindow_OnLoad(elementid);
    to make RTE control editable.

    ReplyDelete
  2. I tried to use it from a Standard webpart page(.cs fille).But it didn't work.
    Any suggestion would be highly appreciated...

    ReplyDelete