Friday 14 March 2014

On Exception/Success time move Success or Error Message page in share point 2010

  • Add the following Namespace.
     
    • using Microsoft.SharePoint.Utilities;
  • Replace the code for btnSuccess_Click event with the following
    SPUtility.TransferToSuccessPage("Operation Completed Successfully");
     
  • Replace the code for btnError_Click event with the following
    or 
       Try - Catch Exception
       Exception ex = new Exception("Operation Failed - Contact to Your Administrator.");
       SPUtility.TransferToErrorPage(ex.Message);
 

  • Build and deploy the solution.

Wednesday 22 January 2014

Print page For specific control on asp.net page


<head>
 
<script type="text/javascript">
        function PrintPanel() {
 
            var panel = document.getElementById("<%=pnlContents.ClientID %>");
//            var printWindow = window.open('', '', 'height=1000,width=1000');
            var printWindow = window.open('', '', 'height=1,width=1');
            printWindow.document.write('<html><head><title>OPD Form</title>');
            printWindow.document.write('</head><body >');
            printWindow.document.write(panel.innerHTML);
            printWindow.document.write('</body></html>');
            printWindow.document.close();
            printWindow.focus();
            printWindow.print();
            printWindow.close();
 
            setTimeout(function () {
                printWindow.print();
            }, 500);
            return false;
        }
</script>
 
 
 
</head>
 
<body>
 
    <asp:Button ID="ButtonSubmitTop" runat="server" class="btnSubmit" Text="Submit" />
    <%--<asp:Button ID="btnPrint" class="btnSubmit" runat="server" Text="Print" OnClientClick="return PrintPanel();"
        CausesValidation="false" />--%>
        <asp:Button ID="btnPrint" class="btnSubmit" runat="server" Text="Print"
        CausesValidation="false" onclick="btnPrint_Click"
  />
  
        <asp:Panel ID="pnlContents" runat="server">
 
    <table class="tblGrid" width="800px">
   
 <table class="tblGrid" width="800px">
        <tr>
            <td class="formtdHeading" valign="top">
                Description
            </td>
            <td colspan="3">
                <asp:TextBox ID="txtDescription" runat="server"  Width="680px"
                    Height="100px" TextMode="MultiLine"></asp:TextBox><asp:RequiredFieldValidator ID="RequiredFieldValidator1"
                        runat="server" ErrorMessage="*" ControlToValidate="txtDescription" Display="Dynamic"></asp:RequiredFieldValidator>
           
            </td>
        </tr>
<tr>
      
          <asp:UpdatePanel ID="UpdatePanel1" runat="server">
                    <ContentTemplate>
                        <asp:GridView ID="gridview1" runat="server"  AutoGenerateColumns="False"
                           
                        </asp:GridView>
                    </ContentTemplate>
                </asp:UpdatePanel>
            </td>
        </tr>
       
</table>
 
</asp:Panel>
 
 
 
</body>
 
 
 
Code Behind File On button Control:
 
protected void btnPrint_Click(object sender, EventArgs e)
        {
            Gridview1.Enabled = true;
            cmbAStatus.Enabled = true;
 
            txtDesc.Enabled = true;
            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(@"<script language='javascript'>");
            sb.Append(@"PrintPanel();");
            sb.Append(@"</script>");
            System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(), "PrintPanels", sb.ToString(), false);
            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", @"window.frameElement.commitPopup();", true);
       
        }