Friday 19 April 2013

how to find factoral of large numbers


#include<stdio.h>
#include<conio.h>
#define MAX 10000
void factorial(int);
void multiply(int);
int l = 0;
int fact[MAX];

int main(){
    int n;
    int i;

    printf("Enter any integer number : ");
    scanf("%d",&n);
   
    fact[0]=1;

    factorial(n);
   
    printf("Factorial is : ");
    for(i=l;i>=0;i--){
         printf("%d",fact[i]);
    }
    return 0;
}
void factorial(int n){
    int i;
    for(i=2;i<=n;i++){
         multiply(i);
    }
}
void multiply(int n){
    long i,r=0;
    int arr[MAX];
    for(i=0;i<=l;i++){
                arr[i]=fact[i];
        }

    for(i=0;i<=l;i++){
         fact[i] = (arr[i]*n + r)%10;
         r = (arr[i]*n + r)/10;
         //printf("%d ",r);
    }
    if(r!=0){
         while(r!=0){
             fact[i]=r%10;
             r= r/10;
             i++;
         }
    }
    l = i-1;   
}

Tuesday 2 April 2013

AsyncFileUpload Control


Ajax (Asynchronous JavaScript and XML) is a new web development technique for interactive websites. With the help of AJAX we can develop web applications and retrieve a small amount of data from the web server. AJAX consists of a different type of technology.
  • JavaScript
  • XML
  • Asynchronous Call to the server
AsyncFileUpload Control
AsyncFileUpload is a new ASP.NET AJAX Control that allows you to asynchronously upload files to server. You don't need a separate upload button for this control. Add the AsyncFileUpload control and a label to the web form for the uploading and displaying of messages respectively. The file uploading results can be checked both in the server and client sides. You can save the uploaded file by calling the SaveAs() method in a handler for the server UploadedComplete event.
Property
  • OnClientUploadComplete
  • OnClientUploadError
  • UploaderStyle
  • CompleteBackColor
  • ThrobberID

Example

Code :
<title> My Ajax APPLICATION</title>  
  <script type = "text/javascript">    
    function uploadComplete(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File Uploaded Successfully";
    }
    function uploadError(sender) {
            $get("<%=lblMesg.ClientID%>").innerHTML = "File upload failed.";}
    }
</script> 
   </head>  
  <body> 
   <form id="form1" runat="server" style="background-color: #453A42">   
 <asp:ScriptManager ID="ScriptManager1" runat="server">    </asp:ScriptManager> 
 <p style="background-color: #FF8080"> ASYNC FILE UPLOAD CONTROL IN AJAX</p>    <br />  
  <div style="background-color: #8C7384">
 <asp:UpdatePanel ID="UpdatePanel1"runat="server">       
 <ContentTemplate>   
 <asp:AsyncFileUpload  ID="AsyncFileUpload1" OnClientUploadComplete="uploadComplete" OnClientUploadError="uploadError"  runat="server" Width="400px" UploaderStyle="Modern" CompleteBackColor = "White" UploadingBackColor="#CCFFFF"  ThrobberID="Image1"OnUploadedComplete = "FileUploadComplete" BackColor="#54AB82" />    
    <asp:Image ID="Image1" runat="server" ImageUrl="~/images......jpg" />    <br />  
 <asp:Label ID="lblMesg" runat="server" BackColor="#CECACD"></asp:Label> 
  </ContentTemplate>  
</asp:UpdatePanel>  
 </div>
</form>

code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void FileUploadComplete(object sender, EventArgs e)
    {
        string filename = System.IO.Path.GetFileName(AsyncFileUpload1.FileName);
        AsyncFileUpload1.SaveAs(Server.MapPath("raj") + filename);
    }
} 

Sample Login form example using asp.net check user name and password


how to implement simple login form to check username and password details of user in database. If user details exist in database then we need to redirect user to welcome page otherwise we need to display “Invalid Username/Password”. Mostly it’s common for all the websites before access the website. I know that many of them feel it’s very easy but for the people who have started learning .NET they don’t know how to implement this because of that I decided to write post to help for the persons who is in need with this requirement. 

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Login Form</title>
</head>
<body>
<form id="form1" runat="server">
Username:
<asp:TextBox ID="txtUserName" runat="server"/>
<asp:RequiredFieldValidator ID="rfvUser" ErrorMessage="Please enter Username"ControlToValidate="txtUserName" runat="server" />
Password:
<asp:TextBox ID="txtPWD" runat="server" TextMode="Password"/>
<asp:RequiredFieldValidator ID="rfvPWD" runat="server" ControlToValidate="txtPWD"
ErrorMessage="Please enter Password"/>
<asp:Button ID="btnSubmit" runat="server" Text="Submit" onclick="btnSubmit_Click" />
</form>
</body>
</html>


protected void btnSubmit_Click(object sender, EventArgs e)
{
SqlConnection con = newSqlConnection(" your connection string");
con.Open();
SqlCommand cmd = new SqlCommand("select * from UserInformation where UserName =@username and Password=@password",con);
cmd.Parameters.AddWithValue("@username", txtUserName.Text);
cmd.Parameters.AddWithValue("@password", txtPWD.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);
if(dt.Rows.Count>0)
{
Response.Redirect("User..aspx",false);
}
else
{
ClientScript.RegisterStartupScript(Page.GetType(), "validation""<script language='javascript'>alert('Invalid Username and Password')</script>");
}
}