Friday, 11 October 2013

Dynamically setting Postback Trigger For the UpdatePanel in Master Page

protected void Page_Init(object sender, EventArgs e)
        {
            PostBackTrigger trigger = new PostBackTrigger();
            trigger.ControlID = btn_export.UniqueID;
            UpdatePanel pnl = (UpdatePanel)Page.Master.FindControl("pnlData");

            //pnldata is the master page UpdatePanel Id.
            pnl.Triggers.Add(trigger);
        }

Restricting the Page from being Postback

<style type="text/css">
    .HideBackGround
    {
    background-color: #696969;
    filter: alpha(opacity=40);
    opacity: 0.7;
    z-index:-1;
    }
</style> 

<asp:ScriptManager ID="script1" runat="server"></asp:ScriptManager>     
<asp:UpdateProgress ID="UpdateProgress" runat="server">
<ProgressTemplate>
<asp:Image ID="img_Progress1" ImageUrl="images/loading.gif" AlternateText="Processing" runat="server" />
</ProgressTemplate>
</asp:UpdateProgress>
<cc1:ModalPopupExtender ID="modalPopup" runat="server" TargetControlID="UpdateProgress"
PopupControlID="UpdateProgress" BackgroundCssClass="HideBackGround" />
<asp:UpdatePanel ID="pnlData" runat="server" UpdateMode="Conditional" >
<ContentTemplate>

Your Content

 </ContentTemplate>
    </asp:UpdatePanel>
    <script type="text/javascript">
        var prm = Sys.WebForms.PageRequestManager.getInstance();
        //Raised before processing of an asynchronous postback starts and the postback request is sent to the server.
        prm.add_beginRequest(BeginRequestHandler);
        // Raised after an asynchronous postback is finished and control has been returned to the browser.
        prm.add_endRequest(EndRequestHandler);
        //     function load() {
        //         Sys.WebForms.PageRequestManager.getInstance().add_endRequest(BeginRequestHandler);
        //         Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
        //     }
        function BeginRequestHandler(sender, args) {
            //Shows the modal popup - the update progress
            var popup = $find('<%= modalPopup.ClientID %>');
            if (popup != null) {
                popup.show();
            }
        }

        function EndRequestHandler(sender, args) {
            //Hide the modal popup - the update progress
            var popup = $find('<%= modalPopup.ClientID %>');
            if (popup != null) {
                popup.hide();
            }
        }
</script> 



Show Alert Message in a page with UpdatePanel

 Inside App_Code     


       public static void ShowMessage(string message)
        {
            Page currentPage = HttpContext.Current.CurrentHandler as Page;

            //If the calling page has updatePanel  
       
            ScriptManager.RegisterClientScriptBlock(currentPage, currentPage.GetType(), "showalert", "alert('" + message + "');", true);
           
           //If the calling page does not have updatePanel

           // ScriptManager.RegisterStartupScript(currentPage,currentPage.GetType(), "showalert", "alert('" + message + "');", true);
        }




If Inside the same Page


      public void showMessage(string Message)
        {
            ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('"+Message+"');", true);

        }


isNull with Cast in Sqlserver

Select        cast(isNull(FR1.Collection,0) as decimal(20,2)) as Collection,
              cast(isNull(FR2.ServiceTax,0) as decimal(20,2)) as ServiceTax,
              cast(isNull(BD.BadDebt,0) as decimal(20,2)) as BadDebt
     From  

(select SUM(CurrentPaid) AS Collection from FeeReceipt where FranchiseCode='DL') FR1,

(select SUM(STax) AS ServiceTax from FeeReceipt where FranchiseCode='DL') FR2,
(select SUM(AMOUNT) as  BadDebt from BadDebt where FranchiseCode='DL'
and VDATE between CONVERT(VARCHAR(15),'03/01/2013',103) AND CONVERT(VARCHAR(15),'10/01/2013',103)) BD

Saturday, 5 October 2013

Hosting a Project in IIS

->Just Copy your Project and Paste it inside c:\Inetpub\wwwroot
->Type Inetmgr in run command
->Go to Sites-Default Website-your Project
->Right click on your Project and set ‘Convert to Application’
->If Your Project Contains DAL and DLL then also convert them into Application by right clicking on it.
-> Enable Directory Browsing (Right Click on Directory Browsing-Open Feature-Enable)
->Right Click on Your Project and then Manage Application-Browse

Friday, 4 October 2013

Use of using statement in c#

  • using is used when you have a resource that you want disposed after it's been used.
  • The using statement obtains the resource specified, executes the statements and
    finally calls the Dispose method of the object to clean up the object.
  • This is basically used to release the  Resources that are no longer in use.
  • When the code block exits the scope of the using statement, Dispose() is called implicitly.
using (SqlConnection con = new SqlConnection(AppConfiguration.ConnectionString))
            {

            }

The above block implicitily convert as follwoing

try
{
SqlConnection con = new SqlConnection(AppConfiguration.ConnectionString)
}
finally
{
if(con!=null)
{
 ((IDisposable)con).Dispose();
}
}

Thursday, 3 October 2013

Finalise vs Dispose

finalise is the process that allows the garbage collector to clean up any unmanaged resources before it is destroyed.
The finalise method can not be called directly; it is automatically called by the CLR. In order to allow more control over the release of unmanaged resources
the .NET framework provides a dispose method which unlike finalise can be called directly by code.

Wednesday, 2 October 2013

Read PDF or Word File

string path = Server.MapPath("Some Useful Javascript Functions.docx");//pdf file or word file path
            WebClient client = new WebClient();
            Byte[] buffer = client.DownloadData(path);
            if (buffer != null)
            {
                Response.ContentType = "application/msword";//To Read Word Files
                Response.ContentType = "application/pdf";//To Read Pdf Files
                Response.AddHeader("content-length", buffer.Length.ToString());
                Response.BinaryWrite(buffer);
            }

Difference Between == and === in Javascript

== only compares values

=== compares values + type


Example

var check1 = '10',
    check2 = 10;

check1 == check2 // true
check1 === check2 // false

Calling server side method after specific time interval in Javascript

<script type="text/javascript">
   var timer;
   function chk_me()
   {

       clearTimeout(timer);
       timer = setTimeout(function validate()
       {
           var name = document.getElementById('<%=txtname.ClientID %>').value;
           var address = document.getElementById('<%=txtaddress.ClientID %>').value;
           PageMethods.ProcessIT(name, address, onSucess, onError);
           function onSucess(result) {
               alert(result);
           }
           function onError(result) {
               alert('Something wrong.');
           }
       }, 1000);
   }
</script>



<form id='form1' runat='server'>
    <asp:ScriptManager ID='ScriptManager1' runat='server' EnablePageMethods='true' />

 <div>
        <p>Say bye-bey to Postbacks.</p>

       
        <asp:TextBox ID="txtname" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtaddress" runat="server"></asp:TextBox>
        <br />
        <asp:Button ID="btnCreateAccount" runat="server" Text="Signup" OnClientClick="HandleIT(); return false;" />
    </div>
    Timer <asp:TextBox ID="txt_1" runat="server"
        onkeyup="chk_me()"></asp:TextBox>
</form>

Breaking a single column into multiple Columns based on a condition in Sql

 select AdmnNo,ReceiptNo,
       convert(varchar(15),ReceiptDate,103) as ReceiptDate,      
       ISNULL((select SUM(CurrentPaid) from FeeReceipt where PaymentMode='cash'
       and ReceiptNo=FR.ReceiptNo and ADMNNO=FR.ADMNNO and ReceiptDate=Fr.ReceiptDate),0) as Cash,
       ISNULL((select SUM(CurrentPaid) from FeeReceipt where PaymentMode='cheque'
      and ReceiptNo=FR.ReceiptNo and ADMNNO=FR.ADMNNO and ReceiptDate=Fr.ReceiptDate),0) as Cheque
      from FeeReceipt FR
      where FR.AdmnNo=150215

Javascript Function to Allow Only Numbers in Textbox

 function isNumber(evt)
    {
        evt = (evt) ? evt : window.event;
        var charCode = (evt.which) ? evt.which : evt.keyCode;
        if (charCode > 31 && (charCode < 48 || charCode > 57)) {
            return false;
        }
        return true;
    }


<asp:TextBox ID="txt_AdmnNo" runat="server" ontextchanged="TextBox1_TextChanged" onkeyup="TextBox1_TextChanged" AutoPostBack="true"
    onkeypress="return isNumber(event)"></asp:TextBox>