0

I have placed a Rich Textbox in SharePoint webpart & on Button click I want to Print the text same as in the format entered by the user which will have certain HTML tags.

For Printing this, I have created an Application Page in my Solution & Placed a Lable on this Page.

On Button Click I want to Pass Textbox value to my Application Page, I have tried the following:

In My webpart, I have tried the following code to pass the values via Query String:

<script>
    function OpenDialPrintLetter() {
        SP.SOD.executeFunc('sp.js', 'SP.ClientContext', showModalPopUpLetter);
    }
     function showModalPopUpLetter() {
        //Set options for Modal PopUp  
         debugger;

         var description = encodeURIComponent('description') + "=" + encodeURIComponent(document.getElementById('<%= txt_description.ClientID %>').innerHTML);
         //var description = document.getElementById('<%= txt_description.ClientID %>').innerHTML;

        var options = {
            //url: '/_layouts/LetterPrint.aspx?description='+description, //Set the url of the page  
            url: '/_layouts/LetterPrint.aspx?' + description, //Set the url of the page  
            title: 'Disciplinary Letter', //Set the title for the pop up  
            allowMaximize: false,
            showClose: true,
            width: 900,
            height: 800
        };
        //Invoke the modal dialog by passing in the options array variable  
        SP.SOD.execute('sp.ui.dialog.js', 'SP.UI.ModalDialog.showModalDialog', options);
     }


</script>

 <input id="INLETTER" type="button" title="Letter" onclick="OpenDialPrintLetter()" value="Print Letter" />

Following is the code of LetterPrint.aspx page:

<script type="text/javascript">
        window.onload = function () {
            window.print();
        }
    </script>
    <div>
        <asp:Label ID="lblReport" runat="server"></asp:Label>
    </div>
</asp:Content>

Following is the CS code of LetterPrint Page which sets the text onto the label on Page Load:

 public string description
        {
            get
            {
                if (!string.IsNullOrEmpty(Request.QueryString["description"]))
                {
                   return Server.UrlDecode(Request.QueryString["description"]);
                   //return Request.QueryString["description"];
                }
                return "";


            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            lblReport.Text = description;
        }

When I am using Encode/Decode, it's showing Nothing on the Page,but without Encode/Decode it is passing some HTML in the URL which is useless

How can I pass the value to the page?

Please Help

Thanks

If I don't Use URLEncode, the following message occurs & the page doesn't open:

The webpage at http://abc:22000/_layouts/LetterPrint.aspx?description=&lt;div%20class="ExternalClass46408EB759074C499EAC82BB2B9EE1AD"&gt;&lt;div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div&gt;&lt;!DOCTYPE%20html&gt;&lt;/div&gt;&lt;div&gt;&lt;html%20lang="en"&gt;&lt;/div&gt;&lt;div&gt;&lt;head&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&lt;title&gt;Bootstrap%20Example&lt;/title&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&lt;meta%20charset="utf-8"&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&lt;meta%20name="viewport"%20content="width=device-width,%20initial-scale=1"&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&lt;link%20rel="stylesheet"%20href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&lt;script%20src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&lt;script%20src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"&gt;&lt;/script&gt;&lt;/div&gt;&lt;div&gt;&lt;style&gt;&lt;/div&gt;&lt;div&gt;.table%20{&lt;/div&gt;&lt;div&gt;&nbsp;%20&nbsp;%20width:%2085%;&lt;/div&gt;&lt;div&gt;&nbsp;%20&nbsp;%20max-width:%20100%;&lt;/div&gt;&lt;div&gt;&nbsp;%20&nbsp;%20margin-bottom:%2010px;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;.boddy%20{&lt;/div&gt;&lt;div&gt;font-size:11px;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;.footer%20{&lt;/div&gt;&lt;div&gt;font-size:13px;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;.table&gt;tbody&gt;tr&gt;td,%20.table&gt;tbody&gt;tr&gt;th,%20.table&gt;tfoot&gt;tr&gt;td,%20.table&gt;tfoot&gt;tr&gt;th,%20.table&gt;thead&gt;tr&gt;td,%20.table&gt;thead&gt;tr&gt;th%20{&lt;/div&gt;&lt;div&gt;border-top:0px;&lt;/div&gt;&lt;div&gt;padding:2px;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;/style&gt;&lt;/div&gt;&lt;div&gt;&lt;/head&gt;&lt;/div&gt;&lt;div&gt;&lt;body%20class="boddy"&gt;&lt;/div&gt;&lt;div&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;br/&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&nbsp;%20&nbsp;%20&nbsp;%20&lt;div%20class="container"&gt;&lt;/div&gt;&lt;div&gt;&nbsp;%20&nbsp;%20&nbsp;%20&nbsp;%20&nbsp;%20&nbsp;&lt;div%20class="row"&gt;&l&IsDlg=1 might be temporarily down or it may have moved permanently to a new web address.

Is there any other way to pass such string to the application page without using Query String Parameter?

Please Help

Thanks

2 Answers 2

0

Try this System.Uri.UnescapeDataString(Request.QueryString["description"]);

Example:-

var description = "%3Cspan%3Edescription%3C%2Fspan%3E"; //Get from QueryString
lblReport.Text =  System.Uri.UnescapeDataString(description); 

Output:-

<span>description</span>
2
  • will that be a good practice to pass such a big text in Query String? is there any other way to pass value from webpart to application page? Mar 1, 2019 at 6:40
  • btw it didn't resolve my issue :(( Mar 1, 2019 at 11:27
0

Do not pass such big string on the URL. instead you can set the txt area value to a local storage and to the LetterPrint.aspx page pass some key to indicate the page has loaded from the previous.

On LetterPrint.aspx page load, check the query string in client side itself and if there is key on the query string get the value from local storage and assign it to label and call window.print.

2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.