Thursday, September 24, 2015

asp.net create masked value

    public static String CreateMaskedValue(string valueForMask, Int32 numberOfCharacter)
        {
            String maskedString = String.Empty;
            int remainingCharCount = (valueForMask.Length - numberOfCharacter) < 0 ? valueForMask.Length : valueForMask.Length - numberOfCharacter;
            if (remainingCharCount > 0)
            {
                if (!string.IsNullOrEmpty(valueForMask))
                {
                    if (valueForMask.Length > 0)
                    {
                        maskedString = string.Concat("".PadLeft(numberOfCharacter, 'x'), valueForMask.Substring(valueForMask.Length - remainingCharCount));
                    }
                }
                return maskedString;
            }
            else
                return valueForMask;


        }

asp.net telerik convert docx to html

   public static string ConvertDocxToHtml(byte[] binaryData)
        {
            DocxFormatProvider docxProvider = new DocxFormatProvider();
            RadFlowDocument flowDoc = docxProvider.Import(binaryData);

            HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
            string result = htmlProvider.Export(flowDoc);

            return result;
        }

Tuesday, September 22, 2015

asp.net fire button click in javascript function pass parameters

1) Javascript function

 function SetDocumentEditorSrc(WrkID) {
                __doPostBack('<%= btnSetRadEditorContent.UniqueID %>', WrkID);
            }

2)  Button Click Event

        protected void btnSetRadEditorContent_Click(object sender, EventArgs e)
        {
            String fileId = Request["__EVENTARGUMENT"]; // parameter
            if (!String.IsNullOrEmpty(fileId))
            {
                String convertedContent = "";

                RxOffice.BLL.Document document = new RxOffice.BLL.Document();
                document.SetRadEditorContent(Convert.ToInt32(fileId));
                if (!String.IsNullOrEmpty(convertedContent))
                {
                    RadEditor1.Content = convertedContent;
                }
            }

            //string filePath = Server.MapPath("~/SampleInitialContent.docx");
            //byte[] fileBinaryData = File.ReadAllBytes(filePath);
            //string convertedContent = Functions.ConvertDocxToHtml(fileBinaryData);

        }

asp.net update panel

1) Update Panel

<asp:UpdatePanel runat="server">
<Triggers>
<asp:AsyncPostBackTrigger ControlID="btnSetRadEditorContent" EventName="Click" />
</Triggers>
<ContentTemplate>
<div style="float: left; width: 59%; margin-left: 10px; border: 1px solid #e2e6eb;">
<%--<iframe id="ifrmWrkDocViewer" src="#" style="height: 430px !important; width: 100%; margin-left: 5px;"></iframe>--%>
<telerik:RadEditor ID="RadEditor1" runat="server" ContentFilters="DefaultFilters, PdfExportFilter">
<ExportSettings FileName="RadEditorExport" OpenInNewWindow="true"></ExportSettings>
</telerik:RadEditor>
<asp:Button ID="btnSetRadEditorContent" runat="server" OnClick="btnSetRadEditorContent_Click" Style="display: none;" />
</div>
</ContentTemplate>
</asp:UpdatePanel>


2) Button click

protected void btnSetRadEditorContent_Click(object sender, EventArgs e)
{
string filePath = Server.MapPath("~/SampleInitialContent.docx");
byte[] fileBinaryData = File.ReadAllBytes(filePath);
string convertedContent = Functions.ConvertDocxToHtml(fileBinaryData);

RadEditor1.Content = convertedContent;
}


3) Javascript Function

 function SetDocumentEditorSrc(WrkID) {
                __doPostBack('<%= btnSetRadEditorContent.UniqueID %>');
            }


asp.net fire button click in javascript function

<asp:Button ID="btnSetRadEditorContent" runat="server" OnClick="btnSetRadEditorContent_Click" Style="display: none;" />


 function SetDocumentEditorSrc(WrkID) {
                __doPostBack('<%= btnSetRadEditorContent.UniqueID %>');
            }


  protected void btnSetRadEditorContent_Click(object sender, EventArgs e)
        {
            string filePath = Server.MapPath("~/SampleInitialContent.docx");
            byte[] fileBinaryData = File.ReadAllBytes(filePath);
            string convertedContent = Functions.ConvertDocxToHtml(fileBinaryData);

            RadEditor1.Content = convertedContent;
        }