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);
       
        }

Tuesday 31 December 2013

The SMTP(GMAIL) server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first.

Gmail requires you to use a secure connection. This can be set in your web.config like this:
<network host="smtp.gmail.com" enableSsl="true" ... />
and Programmatically
            SmtpClient client = new SmtpClient(server, port);
            client.EnableSsl = true;
            client.UseDefaultCredentials = false;
            // Add credentials if the SMTP server requires them.
            client.Credentials = new NetworkCredential(username, password);

Friday 29 November 2013

Passing parameter(Variable value) in ScriptManager.RegisterStartupScript.

Following Steps:

Only Alert:

string _alertValue = "Dear User: Your form" + " " + cmbFormName.SelectedValue.ToString()
                                 + " "      + "successfully";

                    ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW", @"alert('" + _alertValue + "');window.frameElement.commitPopup();", true);



Only Redirect the Page


string ID = 25;
String test = “testabc:80”

string _alertPageRedirect = "http://" + test + "/TestForms/DisplayForm.aspx?ID=" + ID;


Page.ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "window.location.href = '" + _alertPageRedirect + "';", true);

 
Alert With Redirect

Page.ClientScript.RegisterStartupScript(typeof(Page), "MessagePopUp", "alert('Dear User: Please Contact Site Administrator.'); window.location.href = '"+_alertPageRedirect+"';", true);

Monday 21 October 2013

In Datatable Perform GroupBy Function(Grouped Data).

The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns. Aggregate Function ==> CountAggregate Column ==>e.g DateGroup BY Column ==>e.g Month
 // Created GroupBy Method

DataTable GroupBy(string i_sGroupByColumn, string i_sAggregateColumn, DataTable i_dSourceTable) {

DataView dv = new DataView(i_dSourceTable);

// getting distinct values for group column

DataTable dtGroup = dv.ToTable(true, new string[] {

i_sGroupByColumn});


// adding column for the row count

dtGroup.Columns.Add(
"Count", typeof(int));

// looping thru distinct values for the group, counting

foreach (DataRow dr in dtGroup.Rows) {

dr[
"Count"] = i_dSourceTable.Compute(("Count("

+ (i_sAggregateColumn +
")")), (i_sGroupByColumn + (" = \'"
+ (dr[i_sGroupByColumn] +
"\'"))));

}

// returning grouped/counted result

return dtGroup;

}

// end GroupBy

Monday 10 September 2012

How to find Find duplicate value in Array.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace WebApplication4
{
    public partial class _Default : System.Web.UI.Page
    {
        int[] a = new int[5] { 1, 2, 2, 3, 4};


        protected void Page_Load(object sender, EventArgs e)
        {
            int b = 0;
            for (int i = 0; i != (a.Length); i++)
            {

                if (a[i] == 2)
                {
                    b++;
                    Label2.Text = Convert.ToString(b);
                }

                Label1.Text = Label1.Text + " " + a[i];
            }

        }
    }
}

Create GridView With ScrollBars


GridView still have not ScrollBars property. To create GridView with horizontal or vertical scrollbar you need to place GridView inside <div > tag or inside Panel control.

GridView inside <div > HTML tag

To produce GridView scrollbars with div tag, use this code:
<div style="width:100%height:300overflow:auto;">
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</div>

GridView inside Panel Control

To create GridView scrollbars with a little help of Panel control, use this code:
<asp:Panel ID="Panel1" runat="server" ScrollBars="Both" Height="300"Width="100%">
 <asp:GridView ID="GridView1" runat="server">
 </asp:GridView>
</asp:Panel>